首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有以下程序 #include<iostream> #include<string> using namespace std; class base { private: charbaseName[10]; public: base
有以下程序 #include<iostream> #include<string> using namespace std; class base { private: charbaseName[10]; public: base
admin
2010-03-29
19
问题
有以下程序 #include<iostream> #include<string> using namespace std; class base { private: charbaseName[10]; public: base() { strcpy(baseName,"Base"); } virtual char*myName() return baseName; } char *className() { return baseName; } }; class Derived: public base { private: char derivedName[10]; public: Derived() { strcpy(derivedName,"Derived"); } char *myName() { return derivedName; } char *className() { return derivedName; } }; void showPtr(base &p) { cout<<p.myName0<<" "<<p.className(); } int main() { base bb; Derived dd; showPtr(dD) ; retum 0; } 动行后的输出结果为
选项
A、Derived Base
B、Base Base
C、Derived Derived
D、Base Derived
答案
1
解析
本题考核虚函数的应用。类Derived是从基类Base公有派生而来的。因此, Derived是基类Base的子类型。main()函数中定义了一个基类对象bb和一个派生类对象dd。从程序中可看出派生类Derived的对象dd交给了处理基类Base的对象的函数 showPtr进行处理。由于在基类中函数myName被定义成虚函数。所以在函数showPtr中调用的myName函数为派生类的成员函数myName,从而输出Derived。然后输出 className,即基类名称Base。
转载请注明原文地址:https://kaotiyun.com/show/Yhjp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下程序#includevoidfun(char*p,intn){charb[6]="abcde";inti;for(i=0,p=b;i<n;i++)p[i]=b[i];}main(){char
下列描述中正确的是
在数据库管理系统提供的数据语言中,负责数据的查询、增加、删除和修改等操作的是
设有定义:inta;floatb;执行scanf(″%2d%f″,&a,&b);语句时,若从键盘输入876543.0,则a和b的值分别是()。
在长度为n的顺序表中查找一个元素,假设需要查找的元素有一半的机会在表中,并且如果元素在表中,则出现在表中每个位置上的可能性是相同的。则在平均情况下需要比较的次数大约为
以下叙述中错误的是
正确的C语言表达式是()。
在软件开发中,需求分析阶段可以使用的工具是()。
有以下程序段int*p;p=__________malloc(sizeof(int));若要求使p指向一个int型的动态存储单元,在横线处应填入的是()。
算法的有穷性是指()。
随机试题
A.阻遏蛋白结合位点B.激活蛋白CAP结合位点C.两者皆有D.两者皆无大肠埃希菌乳糖操纵子有
李一、李二外出游玩,向李三借进口相机一部。回来天色已晚,李一遂将相机带回家,打算第二天再还。当晚,李四到李一家做客,见此相机,爱不释手,定要以3000元买下,李一见财起意,遂卖之。数日后,李四手头钱紧,向李二以2000元兜售该相机。李二见此相机,甚为眼熟,
商业银行通过同业拆借拆人的资金可以用于哪些用途?
甲向区公安局报案控告乙将其价值10万元的名画盗窃。区公安局以没有证据证明是乙所为不予立案,并发出了不予立案通知书,如果甲不服,他的下述哪些行为符合法律规定?()
一般规定,在自然养护时,对火山灰水泥、粉煤灰水泥、掺有缓凝型外加剂的混凝土,浇水保湿养护日期不得少于()。
货币市场是指专门融通()以内短期资金的场所。
A注册会计师负责审计甲公司2×10年度财务报表,在对销售与收款循环进行审计的过程中,遇到下列问题,请代为做出正确的专业判断。下列关于A注册会计师在应收账款函证中的处理,恰当的是()。
民警罗某于2013年1月3日中午巡逻下班后开着警车回家,因无处停车,就将警车停靠在自家小区附近的禁停路段,后被某市民悄悄贴上手写的“违法行为告知书”,样式非常类似于交警开具的罚单。网民张某用照相机将这一幕拍下来,并上传到微博,引起网民热议。这份
党的十八大指出,中国将继续高举和平、发展、合作、共赢的旗帜,始终不渝地走和平发展道路,坚定奉行独立自主的和平外交政策,始终不渝奉行互利共赢的开放战略,通过深化合作促进世界经济强劲、可持续、平衡增长。我国对外政策的主要目标是
Whereistheman?
最新回复
(
0
)