标题:C++中的class的一个问题,求指导。
取消只看楼主
downeychou
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2013-11-13
结帖率:100%
已结贴  问题点数:10 回复次数:0 
C++中的class的一个问题,求指导。
#include <iostream>
using namespace std;
class Box
{public:
void get_value();
int display();
private:
    int height;
    int width;
    int length;
};
void Box::get_value()
{cin>>height;
cin>>width;
cin>>length;}
int  Box::display()
{return (height*width*length);}
int main()
{Box box1;
box1.get_value();
cout<<box1.display()<<endl;
return 0;
}


这是一个用键盘输入长宽高,求体积的题,为什么我在public中定义一个构造函数:
Box(int h,int w,int l):height(h),width(w),length(l){}
就不能运行了呢?
错误显示为 error C2512: 'Box' : no appropriate default constructor available

求指导,
 还有个问题,有没有什么程序能使编译时出错的问题用中文表达出来?谢谢!
搜索更多相关主题的帖子: private display include public return 
2013-12-07 20:36



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-424855-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.106190 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved