#include <iostream>
using namespace std;
class Base
{
public:
virtual void show()
{
cout<< "base show" <<endl;
}
};
class Derived:public Base
{
public:
void show()
{
cout<< "derived show0" << endl;
}
};
int main()
{
Base *b = new Base;
Base *d = new Derived;
b->show();
d->show();
}
base show
derived show
本文通过 C++ 代码示例介绍了虚函数的概念及使用方法。演示了基类和派生类中虚函数的行为差异,特别是在多态上下文中的表现。
1753

被折叠的 条评论
为什么被折叠?



