程序代码:
#include <iostream>
using namespace std;
class A
{
public:
A (int a)
{
n = a;
cout << "\tEnter class A constructor..." << endl;
cout << "Quit class A constructor..." << endl;
}
protected:
int n;
};
class B : public virtual A
{
public:
B (int b) : A (b)
{
cout << "\tEnter class B constructor... " << n << endl;
cout << "Quit class B constructor..." << endl;
}
};
class C : public virtual A
{
public:
C (int c) : A (c)
{
cout << "\tEnter class C constructor... " << n << endl;
cout << "Quit class C constructor..." << endl;
}
};
class D : public B, public C
{
public:
D (int d):B(d), C(d),A(d)
{
cout << "\tEnter class D constructor... " << n << endl;
cout << "Quit class D constructor..." << endl;
}
};
int main ()
{
D d(28);
return 0;
}