自考新教材-p242_4

源程序:

#include <iostream>
using namespace std;

class CB
{
int b;
public:
CB(int n)
{
b = n;
cout << "CB::b=" << b << endl;
}
~CB()
{
cout << "CB的对象在消亡" << endl;
}
};

class CC
{
int c;
public:
CC(int n1, int n2)
{
c = n1;
cout << "CC::c=" << c << endl;
}
~CC()
{
cout << "CC的对象在消亡" << endl;
}
};

class CD :public CB, public CC
{
int d;
public:
CD(int n1, int n2, int n3, int n4) :CC(n3, n4), CB(n2)
{
d = n1;
cout << "CD::d=" << d << endl;
}
~CD()
{
cout << "CD的对象在消亡" << endl;
}
};
int main()
{
CD CDobj(2,4,6,8);
system("pause");
return 1;
}

运行结果:

原文地址:https://www.cnblogs.com/duanqibo/p/12260543.html