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

阅读如下的程序:
#include <iostream>
using namespace std;
struct B
{
    int i;
    virtrual int f()
    {
        cout << "1";
        return 1;
    }
    virtual const B &f() const
    {
        cout << "2";
        return *this;
    }
    int g()
    {
        cout << "3";
        return 3;
    }
};
struct D: B
{
    int i;
    int f()
    {
        cout << "4";
        return 4;
    }
    const B &f() const
    {
        cout << "5";
        return *this;
    }
    int f(int = 0)
    {
        cout << "6";
        return 6;
    }
    virtual int g()
    {
        cout << "7";
        return 7;
    }
};
int main()
{
 D d;
    const D d_const;
    B b, *p = &d;
    const B *p_const = &d_const;
    b. f();
    p->f();
    p->g();
    p_const->f();
    d_const. f();
}

该程序的输出为:
  • 13455
  • 14355
  • 12345
  • 12336
  • 14736

     举报   纠错  
 
切换
1 个答案

B,类的动态联编与静态联编

 
切换
撰写答案