| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 764 人关注过本帖
标题: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
快速回复:C++中的class的一个问题,求指导。
数据加载中...
 
   



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

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