小编Has*_*nat的帖子

为什么不能在编译时解决运行时多态?

考虑:

#include<iostream>
using namespace std;

class Base
{
    public:
        virtual void show() { cout<<" In Base \n"; }
};

class Derived: public Base
{
    public:
       void show() { cout<<"In Derived \n"; }
};

int main(void)
{
    Base *bp = new Derived;
    bp->show();  // RUN-TIME POLYMORPHISM
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

为什么这段代码会导致运行时多态性,为什么不能在编译时解决它?

c++ polymorphism

73
推荐指数
5
解决办法
5543
查看次数

标签 统计

c++ ×1

polymorphism ×1