欢迎光临
我们一直在努力

计算机阅读该程序,给出程序的输出结果。 #include <iostream.h> class B { public:     virtual void fun1()     {         cout<<"B::fun1().n";     }     virtual void fun2()     {         cout<<"B::fun2().n";     }     void fun3()     {         cout<<"B::fun3().n";     }     void fun4()     {         cout<<"B::fun4().n";     } }; class D:public B { public:     void fun1()     {         cout<<"D::fun1().n";     }     void fun2()     {         cout<<"D::fun2().n";     }     void fun3()     {         cout<<"D::fun3().n";     }     void fun4()     {         cout<<"D::fun4().n";     } }; void main() {     B *pb;     D d;     pb=&d;     pb->fun1();     pb->fun2();     pb->fun3();     pb->fun4(); }-笔试面试资料

本站提供程序员计算机面试经验学习,笔试经验,包括字节跳动/头条,腾讯,阿里,美团,滴滴出行,网易,百度,京东,小米,华为,微软等互联网大厂真题学习背诵。

答案:

这是qklbishe.com第4967 篇笔试面试资料
提供答案分析,通过本文《阅读该程序,给出程序的输出结果。 #include <iostream.h> class B { public:     virtual void fun1()     {         cout<<"B::fun1().n";     }     virtual void fun2()     {         cout<<"B::fun2().n";     }     void fun3()     {         cout<<"B::fun3().n";     }     void fun4()     {         cout<<"B::fun4().n";     } }; class D:public B { public:     void fun1()     {         cout<<"D::fun1().n";     }     void fun2()     {         cout<<"D::fun2().n";     }     void fun3()     {         cout<<"D::fun3().n";     }     void fun4()     {         cout<<"D::fun4().n";     } }; void main() {     B *pb;     D d;     pb=&d;     pb->fun1();     pb->fun2();     pb->fun3();     pb->fun4(); }-笔试面试资料》可以理解其中的代码原理,这是一篇很好的求职学习资料
本站提供程序员计算机面试经验学习,笔试经验,包括字节跳动/头条,腾讯,阿里,美团,滴滴出行,网易,百度,京东,小米,华为,微软等互联网大厂真题学习背诵。

答案:

阅读该程序,给出程序的输出结果。

#include <iostream.h>

class B

{

public:

    virtual void fun1()

    {

        cout<<"B::fun1().n";

    }

    virtual void fun2()

    {

        cout<<"B::fun2().n";

    }

    void fun3()

    {

        cout<<"B::fun3().n";

    }

    void fun4()

    {

        cout<<"B::fun4().n";

    }

};

class D:public B

{

public:

    void fun1()

    {

        cout<<"D::fun1().n";

    }

    void fun2()

    {

        cout<<"D::fun2().n";

    }

    void fun3()

    {

        cout<<"D::fun3().n";

    }

    void fun4()

    {

        cout<<"D::fun4().n";

    }

};

void main()

{

    B *pb;

    D d;

    pb=&d;

    pb->fun1();

    pb->fun2();

    pb->fun3();

    pb->fun4();

}

阅读该程序,给出程序的输出结果。      #include &lt;iostream.h&gt;      class B      {      public:           virtual void fun1()           {               cout&lt;&lt;&quot;B::fun1().n&quot;;           }           virtual void fun2()           {               cout&lt;&lt;&quot;B::fun2().n&quot;;           }           void fun3()           {               cout&lt;&lt;&quot;B::fun3().n&quot;;           }           void fun4()           {               cout&lt;&lt;&quot;B::fun4().n&quot;;           }      };      class D:public B      {      public:           void fun1()           {               cout&lt;&lt;&quot;D::fun1().n&quot;;           }           void fun2()           {               cout&lt;&lt;&quot;D::fun2().n&quot;;           }           void fun3()           {               cout&lt;&lt;&quot;D::fun3().n&quot;;           }           void fun4()           {               cout&lt;&lt;&quot;D::fun4().n&quot;;           }      };      void main()      {           B *pb;           D d;           pb=&amp;d;           pb-&gt;fun1();           pb-&gt;fun2();           pb-&gt;fun3();           pb-&gt;fun4();   }-笔试面试资料 区块链毕设学生286918393号
基类指针指向派生类对象时,派生类会对基类的virtual函数重新编译;

D::fun1().
D::fun2().
B::fun3().
B::fun4().

2020-12-21 21:18:56 回复(0)

文章部分来自互联网,侵权联系删除
www.qklbishe.com

赞(0)
未经允许不得转载: 京大飞辅助网程序员面试-区块链javago面经 » 计算机阅读该程序,给出程序的输出结果。 #include <iostream.h> class B { public:     virtual void fun1()     {         cout<<"B::fun1().n";     }     virtual void fun2()     {         cout<<"B::fun2().n";     }     void fun3()     {         cout<<"B::fun3().n";     }     void fun4()     {         cout<<"B::fun4().n";     } }; class D:public B { public:     void fun1()     {         cout<<"D::fun1().n";     }     void fun2()     {         cout<<"D::fun2().n";     }     void fun3()     {         cout<<"D::fun3().n";     }     void fun4()     {         cout<<"D::fun4().n";     } }; void main() {     B *pb;     D d;     pb=&d;     pb->fun1();     pb->fun2();     pb->fun3();     pb->fun4(); }-笔试面试资料

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址