类的多基类继承

#include<iostream>
using namespace std;
class A
{
private:
	int x;
public:
	A ( int a = 0)
	{
		cout<<"A的构造函数被调用"<<endl;
		x = a;
	}
	void print()
	{
		cout<<x<<endl;
	}

};
class B
{
public:
	B ()
	{
		cout<<"B的构造函数被调用"<<endl;
	}
	void print()
	{
		cout<<"haha!"<<endl;
	}
};
class C :public A , public B				//累c 继承了 类 A  和类 B   
{
private:
	int y;
public:
	C ( int a = 0): A(   ), B()
	{
		cout<<"C的构造函数被调用"<<endl;
		y = a; 
	}
	void print()
	{
		cout<<y<<endl;
	}

};
int main()
{
	C c ( 18 );
	c.print ();
	c.A::print ();
	c.B::print ();

	return 0;
}
/*----------------------------------
2013年11月1日 20:10:02
好久没学习了。 最近就是不想学。。。  很乱。
-----------------------------------------------*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值