/*
* 程序的版权和版本声明部分
* Copyright (c)2013, 烟台大学计算机学院学生
* All rightsreserved.
* 文件名称:score.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;}
static int height;
int width;
int length;
};
int Box::height=10;
int main()
{
Box a(2 ,7), b(3,4);
cout<<a.height<<endl;
cout<<b.height<<endl;
cout<<Box::height<<endl;
cout<<"volume is "<<b.volume()<<endl;
return 0;
}
运行结果:
心得体会:静态数据成员,呢嫩。。。。。