C++多继承(实际开发不建议使用)

多继承可能引发父类中有同名成员的出现,需要加作用域区分

#include 
#include 
using namespace std;

class Base
{
public:
	Base() {
		m_A = 100;
	}
	int m_A;
};


class Base2 {
public:
	Base2()
	{
		m_A = 200;
	}
	int m_A;
};

class Son: public Base,public Base2
{
public:
	Son()
	{
		m_C = 300;
		m_D = 400;
	}
	int m_C ;
	int m_D ;

};

void test01()
{
	Son s;
	cout << "sizeof Son = " << sizeof(s) << endl;
	cout << s.Base::m_A<< endl;
	cout << s.Base2::m_A << endl;
	cout << s.m_C << endl;
}
int main()
{
	test01();
	return 0;
}


你可能感兴趣的:(C,c++,算法,开发语言)