求助一道C++编程题QAQ
2个回答
展开全部
A、B、C、D、E类之间的继承关系为:
B继承C
A继承C
D继承A
E继承B、D
C++程序:
#include "iostream"
using namespace std;
class C
{
public:
C()
{
cout<<"C()"<<endl;
}
~C()
{
cout<<"~C()"<<endl;
}
};
class A : public C
{
public:
A()
{
cout<<"A()"<<endl;
}
~A()
{
cout<<"~A()"<<endl;
}
};
class B : public C
{
public:
B()
{
cout<<"B()"<<endl;
}
~B()
{
cout<<"~B()"<<endl;
}
};
class D : public A
{
public:
D()
{
cout<<"D()"<<endl;
}
~D()
{
cout<<"~D()"<<endl;
}
};
class E : public B, D
{
public:
E()
{
cout<<"E()"<<endl;
}
~E()
{
cout<<"~E()"<<endl;
}
};
int main()
{
E e;
return 0;
}
运行测试:
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询