经典指数          
原因
2283
浏览数
0
收藏数
 

写出程序的运行结果

#include<iostream>
using namespace std;

class Base
{
    int x;
public:
    Base(int b): x(b) {}
    virtual void display()
    {
        cout << x;
    };
};
class Derived: public Base
{
    int y;
public:
    Derived(int d): Base(d), y(d) {} void display()
    {
        cout << y;
    }
};

int main()
{
    Base b(1);
    Derived d(2);
    Base *p = & d;
    b.display();
    d.display();
    p->display();
    return 0;

}



  • 121
  • 222
  • 122
  • 运行出错

     举报   纠错  
 
切换
1 个答案

C 考察虚函数

 
切换
撰写答案