C++继承中的对象模型
发布日期:2021-05-09 23:39:53 浏览次数:18 分类:精选文章

本文共 387 字,大约阅读时间需要 1 分钟。

问题:从父类继承过来的成员,哪些属于子类对象中?

首先我们先看这段代码:

#include 
using namespace std;//继承中的对象模型class Base { public: int m_A; protected: int m_B; private: int m_C;};class Son : public Base { public: int m_D;};void test01() { cout << "size of Son = " << sizeof(Son) << endl;}int main() { test01(); return 0;}

结果为16

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

上一篇:C++继承中构造和析构顺序
下一篇:C++继承的继承方式

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2025年04月07日 15时20分39秒