#include<iostream> using namespace std ; class Base { int basee ; public: Base(int base) { cout<<"Initializing Base..."<<endl; this->basee = base ; } void show() { cout<<basee<<endl; } }; class Base1 : virtual public Base { int base11 ; public: Base1(int base1 ,int base1base ):Base(base1base) { this->base11 = base1 ; cout<<"Initializing Base1..."<<endl; } }; class Base2:virtual public Base { int base22 ; public: Base2(int base2, int base2base):Base(base2base) { this->base22 = base2 ; cout<<"Initializing Base2...."<<endl; } }; class Derived : public Base1, public Base2 { int derived ; public: Derived(int derivied , int derivedbase , int base1 , int base1base , int base2 , int base2base ) : Base(derivedbase),Base1(base1,base1base),Base2(base2,base2base) { cout<<"Initializing Derived..."<<endl; this->derived = derivied; } }; int main() { int derivied = 1 ; int derivedbase = 2 ; int base1 = 3 ; int base1base = 4 ; int base2 = 5 ; int base2base = 6 ; Derived d(derivied , derivedbase,base1,base1base,base2,base2base); d.show(); return 0 ; }
输出为 derivedbase=2