/*
* 程序的版权和版本声明部分
* Copyright (c)2013, 烟台大学计算机学院学生
* All rightsreserved.
* 文件名称: object.cpp
* 作者:杨晨
* 完成日期: 2013年4 月 12日
* 版本号: v1.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;
}
输出结果:
心得体会:
对于static静态数据成员在初始化时要注意要单独初始化。像以上的形式