📜  C ++ |虚函数|问题3

📅  最后修改于: 2021-06-28 21:10:25             🧑  作者: Mango

以下程序的输出

#include
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, b;
    Derived d;
    bp = &d;
    bp->show();
    bp = &b;
    bp->show();
    return 0;
}

(一种)

In Base 
In Base 

(B)

In Base 
In Derived

(C)

In Derived
In Derived

(D)

In Derived
In Base 

答案: (D)
说明:最初,基本指针指向派生的类对象。后来它指向基类对象,
这个问题的测验

想要从精选的最佳视频中学习和练习问题,请查看《基础知识到高级C的C基础课程》。