#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();
// 如果子类中有和父类同名的函数,则父类中所有的同名函数都会被隐藏
}
c++ 学习 之 继承中同名变量和同名函数的处理
最新推荐文章于 2024-07-17 20:43:45 发布