#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
// 继承中的对象模型
class Base
{
public:
Base()
{
m_A = 10;
}
void fun()
{
cout << "Base 里面 的fun" << endl;
}
int m_A ;
};
class Son :public Base
{
public:
Son()
{
m_A = 200;
}
void fun()
{
cout << "Son 里的 fun " << endl;
}
void fun(int a)
{
cout << "son 里带参数的fun " << endl;
}
int m_A;
};
int main() {
Son p;
cout << " Son:: m_A :" << p.m_A << endl;
cout << sizeof(p) << endl;
cout << " Base:: m_A " << p.Base::m_A << endl;
p.fun();
p.Base::fun();
// 如果子类中有和父类同名的函数,则父类中所有的同名函数都会被隐藏
}
01-09
353
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-25
1678
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交