注册 登录
编程论坛 C++教室

[求助]新手求助,还望各位指点一下。谢谢。

anoldyan 发布于 2007-11-02 23:23, 590 次点击

这次我真的不清楚问题出在哪儿了。

//Listing 5.7 - demonstrates use
//of default parameter values
#include <iostream>

int AreaCube(int length,int width = 25,int height = 1);

int main()
{
int length = 100;
int width = 50;
int height = 2;
int area;

area = AreaCube(length,width,height);
std::cout << "First area equals:" << area << "\n";

area = AreaCube(length,width);
std::cout << "Second time area equals:" << area << "\n";

area = AreaCube(length);
std::cout << "Third time area equals:" << area << "\n";
char response;
std::cin >> response;
return 0;
}

AreaCube(int length,int width,int height)
{

return (length*width*height);
}


编译提示: ISO C++ forbids declaration of `AreaCube' with no type ,而且提示出错的地方是倒数第四行的{

7 回复
#2
hegj2007-11-02 23:28

int AreaCube(int length,int width,int height)
{

return (length*width*height);
}

加个int在前面

#3
六道2007-11-03 00:16
声明和定义函数要一样的,声明中可以省略函数的参数,但是类型不可省~
#4
duffebear2007-11-03 12:15

顶2、3楼

#5
无缘今生2007-11-03 14:09

此种错误实在是……
我也犯过,连自己都气愤,当发现的时候。

#6
o0花生0o2007-11-03 14:38
我在vc++上运行没有发现错误
#7
a217zxg2007-11-03 20:54
  好就好在,其缺省情况就是int型,不然就不行了。
#8
anoldyan2007-11-05 09:18
谢谢各位的指点!看来书上的东西也不能完全照搬。
1