首页 > 试题广场 > 写出下列程序的运行结果 class A{ int ax;
[问答题]
写出下列程序的运行结果
class A{
int ax;
public:
A(int x=10){ax=x;cout<<"调用构造函数A"<<ax<<' ';}
void f(){cout<<ax<<' ';}
virtual ~A(){cout<<"调用析构函数A"<<' ';}
};
class B:virtual public A{
int bx;
public:
B(int x):A(20){bx=x;cout<<"调用构造函数 B"<<bx<<' ';}
void f(){cout<<bx<<' ';}
~B(){cout<<"调用析构函数B"<<' ';}
};
class C:virtual public A{
int cx;
public:
C(int x):A(30){cout<<"调用构造函数 C"<<cx<<' ';}
void f(){cout<<cx<<' ';}
~C(){cout<<"调用析构函数C"<<' ';}
};
class D:public B, public C{
int dx;
public:
D(int x,int y,int z):B(x),C(y){dx=z;cout<<"调用构造函数 D"<<dx<<' ';}
void f(){cout<<dx<<' ';}
~c(){cout<<"调用析构函数D"<<' ';}
};
void main{
A*pa=new D(20,30,40);
cout<<endl;
delete pa ;

这道题你会答吗?花几分钟告诉大家答案吧!