#include <iostream>
class Father {
public:
Father() {};
virtual void Say()
{
std::cout << "I'm father!" << std::endl;
}
};
class Son :public Father {
public:
Son() {};
void Say()
{
std::cout << "I'm son..." << std::endl;
}
};
int main()
{
Father * someBody = new Son();
someBody->Say();
system("pause");
}
C++基础 多态实现——利用虚方法实现父类指针调用子类方法
于 2022-04-10 16:47:38 首次发布