#include <iostream> using namespace std; class Base { public: Base(char i) { cout<<"Base constructor. --"<<i<<endl; } }; class Derived1:virtual public Base { public: Derived1(char i,char j):Base(i) { cout<<"Derived1 constructor. --"<<j<<endl; } }; class Derived2:virtual public Base { public: Derived2(char i,char j):Base(i) { cout<<"Derived2 constructor. --"<<j<<endl; } }; class MyDerived:public Derived1,public Derived2 { public: MyDerived(char i,char j,char k,char l,char m,char n,char x): Derived2(i,j), Derived1(k,l), Base(m), d(n) { cout<<"MyDerived constructor. --"<<x<<endl; } private: Base d; }; int main() { MyDerived obj('A','B','C','D','E','F','G'); return 0; }
运行结果:
B和D的输出是就近原则?
原文地址:http://blog.csdn.net/ljd939952281/article/details/45949885