回复 4楼 寒风中的细雨
程序代码:
#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 A
{
public:
B (int b) : A (b)
{
cout << "\tEnter class B constructor... " << n << endl;
cout << "Quit class B constructor..." << endl;
}
};
class C : public 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)
{
cout << "\tEnter class D constructor... " << n << endl; //为什么B类跟C类都可以调用A类的n,而D类不能用A类的n?
cout << "Quit class D constructor..." << endl;
}
};
int main ()
{
D d(28);
}
高手请指点