一个很BT的程序,但是有助于搞清楚构造和析构的基本概念,来,做做看,写出这个程序的结果来!
明天公布答案。
#include <iostream>
class B1
{
public:
B1(int i)
{
std::cout<<"constructing B1 "<<i<<std::endl;
}
~B1()
{
std::cout<<"destructing B1"<<std::endl;
}
};
class B2
{
public:
B2(int j)
{
std::cout<<"constructing B2 "<<j<<std::endl;
}
~B2()
{
std::cout<<"destructing B2"<<std::endl;
}
};
class B3
{
public:
B3()
{
std::cout<<"constructing B3 *"<<std::endl;
}
~B3()
{
std::cout<<"destructing B3"<<std::endl;
}
};
class C:public B2,public B1,public B3
{
public:
C(int a,int b,int c,int d):B1(a),memberB2(d),memberB1(c),B2(b){};
private:
B1 memberB1;
B2 memberB2;
B3 memberB3;
};
int main()
{
C obj(1,2,3,4);
return 0;
}