C++-继承中的对象模型

父类中所有的非静态成员属性都会被子类继承下去,父类中的私有成员属性,是被编译器隐藏了,因此访问不到,但是确实被继承了下去。

#include <iostream>
using namespace std;
class Father
{
public:
	int A;
private:
	int B;

};

class  Son:public Father
{
public:
	int C;
};


int main()
{
	cout << sizeof(Son) << endl;
}

输出结果:

12

  

posted @ 2021-02-07 15:11  围墙外的世界  阅读(84)  评论(0编辑  收藏  举报