首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include using namespace std; class vehicle{ public: virtual int wheels()eonst{return 0;} };
有如下程序: #include using namespace std; class vehicle{ public: virtual int wheels()eonst{return 0;} };
admin
2017-02-18
39
问题
有如下程序:
#include
using namespace std;
class vehicle{
public:
virtual int wheels()eonst{return 0;}
};
class Car:public Vehicle{
public:
int wheels()eonst{return 4;}
};
void f1(Vehicle v){cout<
void f2(Vehicle&v){cout<
void f3(Vehicle*pv){cout<
wheels()<<’’;}
int main(){
Car c;
f1(c);t2(c);t3(&c);
return 0;
}
运行后的输出结果是( )。
选项
A、4 4 4
B、0 4 4
C、4 0 4
D、4 4 0
答案
B
解析
C++中,成员函数调用要触发多态需要满足两个条件:①被调用的成员函数必须是虚成员函数。②必须通过基类类型的引用或指针进行函数调用。
题意中,main()函数首先构造Car对象c,然后将对象c传给三个函数f1()、f2()和f3(),其中f1()的参数是基类类型对象,函数体中调用的是基类的成员函数,输出0;12()的参数是基类类型对象的引用,函数体中调用的类成员函数是虚函数,满足多态条件,输出4;f3()的参数是基类类型对象的指针,甬数体中调用的类成员函数是虚函数,满足多态条件,输出4。故本题答案为B选项。
转载请注明原文地址:https://jikaoti.com/ti/fkt0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
在数据管理技术的发展过程中,经历了人工管理阶段、文件系统阶段和数据库系统阶段。其中数据独立性最高的阶段是
面向对象的模型中,最基本的概念是对象和【】。
不合法的main函数命令行参数表示形式是
对于下面的程序ifstreamfin(c:\test.txt);if(fin)cout<<"ok";elsecout<<"wrong";对于if语句中的内容可
以下哪个不是C++语言中的有效标识符()。
下面的说明中,正确的函数定义是()。
下面关于构造函数和析构函数的描述,错误的是()。
下面程序输出的结果为#include"iostream.h"classA{public:A(){cout<<"CLASSA"<<endl;}
执行完下列语句 int a,b, *c=&a; int * &p=c; p=&b; 后c指向
设有如下说明 typedef struct {int n;char c;double x;}STD; 则有以下选项,能正确定义结构体数组并赋初值的语句是
随机试题
简述激励的类型。
某患者血肌酐浓度为88.4μmol/L,尿肌酐浓度为4420μmol/I.,24小时尿量为1584ml,则内生肌酐清除率为
我国宪法规定,()属于国家所有,即全民所有。
下列贷款中,不属于房地产开发贷款的是()。
某建设工程合同约定,“工程通过竣工验收后2个月内,结清全部工程款”。2005年10月1日工程通过竣工验收,10月10日承包人提交竣工结算文件,10月20日承包几将工程移交发包人,但发包人一直未付工程余款。2006年5月1日,承包人将发包人起诉至人民法院,要
道德借以维持的社会力量有()。
河水:氧()
阅读下列说明,回答问题1至问题3,将解答填入答题纸的对应栏内。【说明】某种出售罐装饮料的自动售货机(VendingMaChine)的工作过程描述如下:(1)顾客选择所需购买的饮料及数量。(2)顾客从投币口向自动售货机中投入硬币(该自动售货机只接收
TheHeadlandHypothesisarguesthatforagingornon-agriculturaltribeshavebeenunabletocollectadequatecarbohydrate
C空格前是不定冠词a,空格后是谓语动词invites,因此,空格处应填入名词或起名词作用的词,与a一起作从句的主语。结合上文awoman、aman可知,空格处也应填入表示“人”的单词,再结合空格所在句中的them可知,空格处应填入表示多个人的名词。故C
最新回复
(
0
)