问题及代码:
/* Copyright (c) 2014, 烟台大学计算机学院
* All rights reserved.
* 文件名称:test.cpp
* 作 者:尚 月
* 完成日期:2015年 05 月 24 日
* 版 本 号:v1.0
* 输入程序:阅读下列程序,写出执行结果
* 程序输入:
* 程序输出:按要求输出
*/
#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;
}
运行结果:
Base constructor.-E
Derived1 constructor.-D
Derived2 constructor.-B
Base constructor.-F
MyDerived constructor.--G