如下程序执行后的输出结果是【 】。 #include <iostream> using namespace std; class Base { public: Base(int x,int y)

admin2013-02-27  41

问题 如下程序执行后的输出结果是【  】。
    #include <iostream>
   using namespace std;
   class Base
   {
   public:
       Base(int x,int y)
       {
           a=x;
           b=y;
       }
       void Show()
       {
           cout<<"Base: "<<a<< ’,’ <<b<<"  ";
       }
   private:
       int a,b;
   };
   class Derived : public Base
   {
   public:
       Derived(int x, int y, int z)  :  Base(x,y),c(z) {  }
       void Show()
       {
           cout<<"Derived:"<<c<<end1;
       }
   private:
       int c;
   };
   int main()
   {
       Base b(100,100),*pb;
       Derived d(10,20,30);
       pb=&b;
       pb->Show();
       pb=&d;
       pb->Show();
       return 0;
   }

选项

答案Base:100,100 Base:10,20

解析 本题考核对象指针的应用。主函数中通过对象指针pb.分别调用其类成员函数Show()和派生类成员函数Show()先后输出 Base:100,100Base:10,20。
转载请注明原文地址:https://jikaoti.com/ti/6rE0FFFM
0

最新回复(0)