| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 764 人关注过本帖
标题:C++中的class的一个问题,求指导。
只看楼主 加入收藏
冷读者
Rank: 1
等 级:新手上路
帖 子:19
专家分:5
注 册:2012-10-2
收藏
得分:0 
加上
Box(int h,int w,int l):height(h),width(w),length(l){} 
是可以的。
但是定义一个类的对象的时候就要传入值。如Box box1(10,10,10);
程序代码:
#include <iostream>
using namespace std;
class Box
{
public:
    Box(int h,int w,int l):height(h),width(w),length(l){}

 //   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(10,10,10);

 //   box1.get_value();
    cout<<box1.display()<<endl;
    return 0;
}
2013-12-20 00:17
快速回复:C++中的class的一个问题,求指导。
数据加载中...
 
   



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

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