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

关于构造函数应用举例,请半我看看程序中那错了

ly861014 发布于 2008-11-02 15:55, 751 次点击
#include <iostream>
using namespace std;
class Box
{
public:
Box(int,int,int);
int volume();
private:
int height;
int width;
int length;
};
Box::Box(int h,int w,int len):height(h),width(w),length(len){}
int Box::volume()
{return(height*width*length);
}
int main()
{Box box1(4,5,6);
cout<<"the volume of box1 is "<<box1.volume<<endl;
return 0;
}
2 回复
#2
newyj2008-11-02 16:06
少括号box1.volume()
#3
ly8610142008-11-02 16:35
回复 2# 的帖子
哦,大意,谢谢了啊
1