码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-05-24 10:10:29      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:c++   大一练习   继承和派生   

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

 

 

 

 

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

标签:c++   大一练习   继承和派生   

原文地址:http://blog.csdn.net/ljd939952281/article/details/45949885

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!