文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>C++的多重继承

C++的多重继承

时间:2011-05-22  来源:孤独的猫

有如下的C++代码

#include <iostream>
using namespace std;
class Base
{
public:
Base(
int i) {cout<<"Base constructor called "<<i<<endl;}
~Base(void) {cout<<"Base destructor called"<<endl;}
};

class Base1:public Base
{
public:
Base1(
int i,int j):Base(j) {cout<<"Base1 constructor called "<<i<<endl;}
~Base1(void) {cout<<"Base1 destructor called"<<endl;}
};

class Base2
{
public:
Base2(
int i) {cout<<"Base2 constructor called "<<i<<endl;}
~Base2(void) {cout<<"Base2 destructor called"<<endl;}
};

class Base3
{
public:
Base3(
int i) {cout<<"Base3 constructor called "<<i<<endl;}
~Base3(void) {cout<<"Base3 destructor called"<<endl;}
};

class Derived:public Base2,public Base1,public Base3
{
Base3 member3; Base1 member1; Base2 member2; Base member;
public:
Derived(
int i,int a,int b,int c,int d,int e,int f,int g)
:Base1(g,a),member2(e),member1(g,d),Base2(b),member3(f),Base3(c),member(i)
{
cout
<<"Derived constructor called "<<i<<endl;
}
~Derived(void) {cout<<"Derived destructor called"<<endl;}
};

int main()
{
Derived objD(
1,2,3,4,5,6,7,8);
return 0;
}

用 $ g++ -Wall -o base1 base1.cpp 进行编译

运行 $ ./base1 结果为

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载