//继承时有关构造函数要注意的一些问题
#include <iostream> using std::cout; using std::endl;class Base
{ public: Base(){} Base(int n){} };class C_A1: public Base
{ public: C_A1(){} C_A1(int n0,int n1):Base(n0){} };class C_A0: public Base
{ public: C_A0(){} C_A0(int n0,int n1):Base(n0){} };class C_B0: public C_A0,public C_A1
{ public: C_B0(){}; //若定义了此默认构造函数,则它的基类要定义默认构造函数,若未定义 //此默认构造函数,则它的基类默认构造函数可有可无 C_B0(int n,int n0,int n1,int n2):C_A0(n,n1),C_A1(n0,n2) { } };int main()
{ return 0; }若将上述代码中的C_B0(){}除去,编译时将出现如下的错误 testcpp.cpp: In constructor 'C_B0::C_B0()': testcpp.cpp:201:15: error: no matching function for call to 'C_A0::C_A0()' testcpp.cpp:201:15: note: candidates are: testcpp.cpp:195:9: note: C_A0::C_A0(int, int) testcpp.cpp:195:9: note: candidate expects 2 arguments, 0 provided testcpp.cpp:191:7: note: C_A0::C_A0(const C_A0&) testcpp.cpp:191:7: note: candidate expects 1 argument, 0 provided 编译失败。