#include<iostream>
using namespace std;
class Box
{
public:
Box(double l=2.0,double b=2.0,double h=2.0)
{
cout << "constructor called" << endl;
length = l;
breadth = b;
height = h;
}
double Volume()
{
return length * breadth*height;
}
private:
double length;
double breadth;
double height;
};
int main()
{
Box box1(2.0,1.0,2.0);
Box box2(2.1, 1.2, 2.3);
Box* ptrBox;
ptrBox = &box1;
cout << "Volume of box1:" << ptrBox->Volume() << endl;
ptrBox = &box2;
cout << "Volume of box2:" << ptrBox->Volume() << endl;
return 0;
}

还没有评论,来说两句吧...