首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
若有以下程序: #include <iostream> using namespace std; class Base public: Base() { x=0; } int x; }; class Derivedl: virtua
若有以下程序: #include <iostream> using namespace std; class Base public: Base() { x=0; } int x; }; class Derivedl: virtua
admin
2010-03-29
20
问题
若有以下程序: #include <iostream> using namespace std; class Base public: Base() { x=0; } int x; }; class Derivedl: virtual public Base public: Derived1() { x=10; } }; class Derived2: virtual public Base publici Derived2() x=20; }; class Derived :public Derived1,protected Derived2 {}; int main() Derived obj; cout<<obj.x<<end1; return 0; } 该程序运行后的输出结果是
选项
A、20
B、30
C、10
D、0
答案
1
解析
本题考核虚基类的应用。本题中,虽然Derived1和Derived2都是由共同的基类x派生而来的,但山于引入了虚基类,使得它们分别对应基类的不同副本。这时数据成员x只存在一份拷贝,不论在类Derived1修改,还是在类Derived2中修改,都是直接对这惟一拷贝进行操作。本题程序执行语句“Derived obj”时,就会先调用虚基类Base的构造函数,使得x=0,然后执行类Derived1的构造函数使得x=10,再执行类Derived2的构造函数,使得x=20。最后输出x的值为20。
转载请注明原文地址:https://jikaoti.com/ti/riW0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
若有以下程序#include#defineN4voidfun(inta[][N],intb[],intflag){inti,j;for(i=0;i
在数据库设计中,将E-R图转换成关系数据模型的过程属于()。
在C语言中,变量的隐含存储类别是()。
编写函数fun,其功能是:根据以下公式求P的值,结果由函数值带回。m与n为两个正整数且要求m>n。例如:m=12,n=8时,运行结果为495.000000。注意:部分源程序在文件PROG1.C文件中。请勿改动主函数main和其他函数中的任何内容,
在数据流图中,带有箭头的线段表示的是()。
编写函数fun,其功能是:求ss所指字符串中指定字符的个数,并返回此值。例如,若输入字符串123412132,输入字符为1,则输出3。注意:部分源程序在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你
两个或两个以上的模块之间关联的紧密程度称为()。
设有表示学生选课的三张表,学生S(学号,姓名,性别,年龄,身份证号),课程C(课号,课名),选课SC(学号,课号,成绩),则表SC的关键字(键或码)为()。
下列不属于软件工程3个要素的是()。
在数据库系统的组织结构中,下列()映射把用户数据库与概念数据库联系了起来。
随机试题
A.阳胜则热,阴胜则寒B.阳虚则寒,阴虚则热C.阴盛格阳,阳盛格阴D.阴损及阳,阳损及阴寒热真假证的病机是
使用固体催化剂时一定要防止其中毒,若中毒后其活性可以重新恢复的中毒是()。
可直接激活蛋白激酶C的物质是
寒邪的特点是
将会使债券的发行利率提高的因素有()。
地陪在带领旅游团用第一餐时,应做好的工作有()。
随着现代科技的飞速发展,玩微信、晒微博、软件打车、软件预约家政、互联网支付等新生事物正逐渐融人和改变着人们的生活,但是这些新生事物在带来便利的同时也造成了一些社会问题,政府为此也正在制定相关举措引导他们正常发展。这种情况说明()。
罗杰斯的“有意义学习”与奥苏伯尔的“有意义学习”的区别在于()
清朝的灭亡给中国带来了一个真正的时代,社会震荡,世事忙乱,人们也没有心思去品咂一下这次历史变更的苦涩原味,匆匆忙忙赶路去了。直到1927年6月1日。大学者王国维先生在颐和园投水而死,才让全国的有心人肃然深思。王国维先生的死因众说纷纭,我们且
设f(x)是在区间[1,+∞)上单调减少且非负的连续函数,an=一1nf(x)dx(n=1,2,…).证明:证存在;
最新回复
(
0
)