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

using namespace std;
class Base
{
    int x;
    public:
        Base(int b): x(b) {}
        virtual void display()
        {
            cout << x << endl;
        }
};
class Derived: public Base
{
    int y;
    public:
        Derived(int d): Base(d), y(d) {}
        void display()
        {
            cout << y << endl;
        }
};
int main()
{
    Base b(2);
    Derived d(3);
    b.display();
    d.display();
    Base *p = &d;
    p->display();
    system("pause");
    return 0;
}
上面程序的输出结果是什么?
  • 2 2 3
  • 3 2 2
  • 2 3 3
  • 2 3 2

     举报   纠错  
 
切换
暂时还没有答案,欢迎分享你的解答 . . .
撰写答案
扫描后移动端查看本题
相关题目