myoverload.cpp
来自「Visual C++高级编程及其项目应用开发(含源代码)」· C++ 代码 · 共 34 行
CPP
34 行
#include <iostream>
#include <string>
using namespace std;
class CParent
{
public:
CParent(){};
~CParent(){};
void ShowIt(const string str)
{
cout<<"这是父类!传入的参数是 :"<<str<<endl;
}
};
class CSon : public CParent
{
public:
CSon(){};
~CSon(){};
void ShowIt(const string str)
{
cout<<"这是子类!传入的参数是 :"<<str<<endl;
}
};
void main()
{
CSon myObj;
myObj.ShowIt("Just try!"); //子类重载父类的函数
myObj.CParent::ShowIt("Just try!"); //子类对象调用父类重载函数
return;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?