文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
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 结果为

相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载