首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有以下程序: #include <iostream> using namespace std; class Base { public: Base(){} virtual void f1()
有以下程序: #include <iostream> using namespace std; class Base { public: Base(){} virtual void f1()
admin
2010-03-29
25
问题
有以下程序: #include <iostream> using namespace std; class Base { public: Base(){} virtual void f1() { cout<<"f1 of base"<<end1; } ~Base(){} }; class Derive: public Base { public: void fl(int x) { cout<<"f1 of derive"<<end1; } }; int main ( ) { Base *p; Derive obj1; p=&obj 1; p->f1 ( ); return 0; }
选项
A、编译时出错
B、f1 of derive
C、f1 of base
D、以上答案都不对
答案
2
解析
本程序中,将基类的成员函数n()定义为虚函数,而函数f1()在派生类中被重新定义,重定义的函数仍然是一个虚函数。在C++中,一个基类指针(或引用)可以指向它的派生类对象,而且通过这样的指针或引用调用虚函数时,被调用的是该指针(或引用)实际所指向的对象类的那个重定义版本。
转载请注明原文地址:https://kaotiyun.com/show/EXjp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
设有定义:intx=2;以下表达式中,值不为6的是
有以下程序,程序运行后的输出结果是#include<stdio.h>#defineS(x)4*(x)*x+1voidmain(){intk=5,j=2;printf("%d\n",S(k+j));}
若有以下程序#includeint*f(int*s,int*t){intk:if(*s
设有定义:doublex=2.12;,则以下各项中不能完整输出变量x值的语句是()。
有以下程序#include<stdio.h>#defineN4voidfun(inta[][N],intb[]){inti;for(i=0;i<N;i++)b[i]=a[i][i]-a[i][N-1-i];}voidmain()
设有以下函数:voidfun(intn,char*s){……}则下面对函数指针的定义和赋值均正确的是
C语言中char类型数据占字节数为()。
结构化程序设计的基本原则不包括( )。
软件按功能可以分为:应用软件、系统软件和支撑软件(或工具软件)。下面属于系统软件的是
若变量已正确定义,以下选项中非法的表达式是
随机试题
不宜冷藏的细菌是
患者,女性,36岁。近一段时间出现不规则阴道出血,经量增多,并感到阴道排液也增多,并有恶臭。建议作
新建项目的分项工程质量评定中,关键实测项目的合格率不应低于90%,机电工程的合格率不应低于95%。()
当路基压实度因含水量过大而达不到要求时,应继续碾压。()
以下选项中关于设备制造过程的持续改进叙述正确的是( )。
根据《水利工程质量监督管理规定》(水建[1997]339号),工程质量监督机构监督检查和认定()的划分。
简述格式条款的概念和我国合同法对格式条款的法律要求。
老张、老王、老李、老赵四人的职业分别是司机、教授、医生、工人。老张比教授个子高。老李比老王个子矮。工人比司机个子高。医生比教授个子矮。工人不是老赵就是老李。根据以上条件,可推出以下哪项?
打开工作簿文件Excel.xlsx,将工作表Sheet1的A1:F1单元格合并为一个单元格,内容水平居中,计算“总计”行和“合计”列单元格的内容,将工作表命名为“商品销售数量情况表”。
Withthepossibleexceptionofequalrights,perhapsthemost【C1】______issueacrosstheUnitedStatestodayisthedeathpenalty
最新回复
(
0
)