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

浙公网安备 33010602011771号