从运行结果中可以得到多继承构造函数和析构函数的执行顺序
-
#include <iostream.h>
-
-
class A
-
{
-
private:
-
int a, b;
-
public:
-
A(int aa, int bb):a(aa), b(bb){cout<<"A构造函数"<<endl;}
-
~A(){cout<<"A析构函数"<<endl;}
-
void displayA(){cout<<"A-a = "<<a<<"A-b = "<<b<<endl;}
-
};
-
-
class B
-
{
-
private:
-
int c, d;
-
public:
-
B(int cc, int dd):c(cc), d(dd){cout<<"B构造函数"<<endl;}
-
~B(){cout<<"B析构函数"<<endl;}
-
void displayB(){cout<<"B-c = "<<c<<"B-d = "<<d<<endl;}
-
};
-
-
-
class C:public A, public B
-
{
-
private:
-
int e;
-
public:
-
C(int aa, int bb, int cc, int dd, int ee):A(aa, bb), B(cc, dd), e(ee){cout<<"C构造函数"<<endl;}
-
~C(){cout<<"C析构函数"<<endl;}
-
void displayC(){cout<<"C-e = "<<e<<endl;}
-
};
-
-
int main()
-
{
-
C t(1, 2, 3, 4, 5);
-
t.displayA();
-
t.displayB();
-
t.displayC();
-
-
return 0;
-
}
阅读(1130) | 评论(0) | 转发(0) |