填空题

下列程序的输出结果为2,请将程序补充完整。
#include <iostream>
using namespace std;
class Base
public:
______void fun() cout<<1;
;
class Derived:public Base
public:
void fun()cout<<2;
;
int main()
Base*p=new Derived;
p->fun();
delete p;
return 0;

【参考答案】

virtual
<上一题 目录 下一题>
热门 试题

填空题
在MyClass类的定义中,对赋值运算符;进行重载。请将横线处缺失的部分补充完整。 ______MyClass::operator=(const MyClass& rhs) if(this == &rhs) return *this; value = rhs.value; return *this;
填空题
在下列的程序的横线处填上适当的语句,使该程序的输出为12。 #include<iostream.h> using namespace std; class Base public: int a,b; Base(int i)a=i; ; class Derived:public Base int a; public: Derived(int x):Base(x),b(x+1); void show() ______; 输出基类数据成员a的值。 cout<<b<<endl; ; void main() Derived d(1); d.show(); return 0;
相关试题
  • 下列程序的运行结果为( )。 #include...
  • 下列程序的输出结果是( )。 #include...
  • 有如下程序: #include <iostream> u...
  • 下列程序的运行结果为( )。 #include...
  • 下列程序的输出结果是( )。 #ificlude...