/*
* 程序的版权和版本声明部分
* Copyright (c)2013, 烟台大学计算机学院学生
* All rightsreserved.
* 文件名称: c.cpp
* 作者:耿娜
* 完成日期: 2013年 4 月19 日
* 版本号: v1.0
* 输入描述:
* 问题描述: 静态数据成员的改错
* 程序输出:
*/
错误代码
#include <iostream>
#include <string>
using namespace std;
class Box
{
public:
Box(int h,int w,int l):height(h),width(w),length(l){}
int volume( ){return height*width*length;};
private:
static int height; //静态的数据成员
int width;
int length;
};
int main()
{
Box b(2,3,4);
cout<<"volume is "<<b.volume()<<endl;
return 0;
}
改后的代码
#include <iostream>
#include <string>
using namespace std;
class Box
{
public:
Box(int w,int l):width(w),length(l){}
int volume( ){return height*width*length;};
private:
static int height; //静态的数据成员
int width;
int length;
};
int Box::height =2;
int main()
{
Box b(3,4);
cout<<"volume is "<<b.volume()<<endl;
return 0;
}
第七周上机任务项目1
最新推荐文章于 2013-04-24 19:29:28 发布