#include<iostream>
using namespace std;
class CFather
{
public:
int m_nMoney;
public:
CFather()
{
m_nMoney=999999999;
}
};
class CSon :public CFather
{
public:
int m_nMoney;
public:
CSon()
{
m_nMoney=111111111;
}
};
int main()
{
cout << sizeof(CSon) << endl;
CSon son;
cout << son.m_nMoney <<endl; //不写作用域默认是子类,因为是用子类的对象调用的;
cout << son.CSon::m_nMoney <<endl;
cout << son.CFather:: m_nMoney <<endl; //CFather:: 利用作用域运算符限制是在父类里面的money
system("pause");
return 0;
}
输出结果: