今天看啥
热点:

第12周 程序阅读-多重继承3,第12周阅读继承


#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的输出是就近原则?

 

 

 

 

www.bkjia.comtruehttp://www.bkjia.com/ASPjc/1005659.htmlTechArticle第12周 程序阅读-多重继承3,第12周阅读继承 #include iostreamusing namespace std;class Base{public: Base(char i) { coutBase constructor. --iendl; }};class Derived1:v...

相关文章

帮客评论

视觉看点