您的位置:首页 > 编程语言 > C语言/C++

C++之多继承

2016-03-04 21:06 288 查看
#include <iostream>

using namespace std ; 

class AA
{
	public:
		int a ; 
		void Say_hello(void)	
		{
			cout << "this is AA " << endl ; 	
		}
};

class BB
{
	public:
		int b ; 
		void Say_hello(void)
		{
			cout << "this is BB " << endl ; 
		}
};

//多继承 
class CC  : public AA , public BB
{
	public:
		int d ; 
		void Say_hello(void)
		{
			cout << "this is CC " << endl ; 
		}
};

int main(void)
{
	CC  aa ; 
	aa.Say_hello();
	aa.AA::Say_hello();
	aa.BB::Say_hello();
	aa.CC::Say_hello();

	cout << "Size AA : " << sizeof(AA) << endl ; 
	cout << "Size BB : " << sizeof(BB) << endl ; 
	cout << "Size CC : " << sizeof(CC) << endl ; 
	
}

运行结果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: