/*构造函数和析构函数的调用次序*/
#include<iostream>
using namespace std;
class Box{
public:
Box()
{
length=1;width=2;height=3;
cout<<"Box("<<length<<","<<width<<","<<height<<")";
cout<<"is constructed!"<<endl;
}
Box(float L,float W,float H){length=L;width=W;height=H
cout<<"Box("<<length<<","<<width<<","<<height<<")";}
float Volume(){return length*width*height;}
~Box()
{
cout<<"Box("<<length<<","<<width<<","<<height<<")";
cout<<"is destructed!"<<endl;
}
private:
{
float length,width,height;
};
int main()
{
Box box1(2,3,4);
Box box2;
cout<<"the information of box1 is:"<<box1.Volume<<endl;
cout<<"the information of box2 is:"<<box2.Volume<<endl;
return 0;
}
#include<iostream>
using namespace std;
class Box{
public:
Box()
{
length=1;width=2;height=3;
cout<<"Box("<<length<<","<<width<<","<<height<<")";
cout<<"is constructed!"<<endl;
}
Box(float L,float W,float H){length=L;width=W;height=H
cout<<"Box("<<length<<","<<width<<","<<height<<")";}
float Volume(){return length*width*height;}
~Box()
{
cout<<"Box("<<length<<","<<width<<","<<height<<")";
cout<<"is destructed!"<<endl;
}
private:
{
float length,width,height;
};
int main()
{
Box box1(2,3,4);
Box box2;
cout<<"the information of box1 is:"<<box1.Volume<<endl;
cout<<"the information of box2 is:"<<box2.Volume<<endl;
return 0;
}