https://blog.csdn.net/SHAOYEZUIZUISHAUI/article/details/100525956
重写:
名字一样,参数列表也一样,返回值可以不一样’ 给虚函数实现多态使用
隐藏:
在不同类中,用相同作用名来命名函数,参数不同(类似重载)。但是定义对象来调用,不能像重载一样,使用不同参数来调用。应该用类名+作用域来调用。
#include <iostream>
using namespace std;
void AA()
{
cout << "AA()" << endl;
}
void AA(int a) // 重载
{
cout << "AA(int a)" << endl;
}
class CPerson // 基类(父类)
{
public:
void BB()
{
cout << "CPerson::BB()" << endl;
}
void CC()
{
cout << "CPerson::CC()" << endl;
}
};
class CSuperMan : public CPerson
{
public:
void BB(int b) // 隐藏 (纵向重载)
{
cout << "CPerson::BB(int b)" << endl;
}
void CC() // 重写, 给虚函数实现多态提供
{
cout << "CSuperMan::CC()" << endl;
}
};
int main()
{
AA();
AA(123);
CSuperMan ss;
ss.CSuperMan::BB(123);
ss.CPerson::BB();
ss.CSuperMan::CC();
ss.CPerson::CC();
system("pause");
return 0;
}