#include<iostream>
using namespace std;
class Box
{
public:
static int objectCount;
Box(double l=2.0,double b=2.0,double h = 2.0)
{
cout << "constructor called." << endl;
length = l;
breadth = b;
height = h;
objectCount++;
}
double Volume()
{
return length * breadth*height;
}
static int getCount()
{
return objectCount;
}
private:
double length;
double breadth;
double height;
};
int Box::objectCount = 0;
int main()
{
cout << "initial stage count:" << Box::getCount() << endl;
Box Box1(2.9,2.0,3.4);
Box Box2(2.2, 2.0, 3.4);
Box Box3(2.2, 2.0, 3.4);
cout << "Total Objects:" << Box::objectCount << endl;
return 0;
}
还没有评论,来说两句吧...