代码打印所有的构造函数。我读到构造函数在我们从另一个类派生一个类时没有被继承。那么为什么创造c
从b
和a
为什么构造函数被调用,如果他们没有被继承?
class A
{
public:
A() { cout << "A's constructor called" << endl; }
};
class B
{
public:
B() { cout << "B's constructor called" << endl; }
};
class C: public B, public A // Note the order
{
public:
C() { cout << "C's constructor called" << endl; }
};
int main()
{
C c;
return 0;
}
[C++超类构造函数调用规则]的可能重复(http://stackoverflow.com/questions/120876/c-superclass-constructor-calling-rules) – Soeren