问题:从父类继承过来的成员,哪些属于子类对象中?
父类中的所有非静态成员属性都会被子类继承下去。
父类中私有成员属性是被编译器隐藏了,因此访问不到,但是确实被继承下去了
class Base
{
public:
int m_A;
protected:
int m_B;
private:
int m_C;
};
//公共继承
class Son :public Base
{
public:
int m_D;
};
void test01()
{
//结果为16,即父类中的ABC加上子类中的D。
//父类中的所有非静态成员属性都会被子类继承下去
//父类中私有成员属性是被编译器隐藏了,因此访问不到,但是确实被继承下去了
cout << "size of son = " << sizeof(Son) << endl;
}