首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include using namespace std; class TestClass l { public: TestClass 1 0{cout
有如下程序: #include using namespace std; class TestClass l { public: TestClass 1 0{cout
admin
2021-05-06
33
问题
有如下程序:
#include
using namespace std;
class TestClass l
{
public:
TestClass 1 0{cout<<”TestClass 1”;)
-TestClass l 0{tout<<”~TestClass l”;)
);
class TestClass2:public TestClass l
{
TestClass l*p;
pu
选项
A、TestClass2TestClass 1 TestClass l~TestClass l~TestClass2~TestClass 1
B、TestClasslTestClass2TestClassl~TestClass2~TestClass l~TestClass l
C、TestClass2TestClasslTestClassl~TestClass2~TestClass l~TestClass 1
D、TestClass 1 TestClass2TestClas l-~TestClass 1~TestClass2~TestClass l
答案
B
解析
派生类中构造函数的执行顺序是:先调用基类构造函数,对基类数据成员初始化,然后调用子对象构造函数,对子对象数据成员初始化;最后执行派生类构造函数本身,对派生类数据成员初始化。由主函数main入手,首先定义了一个TestClass2对象obi。其中TestClass2公共继承TestClassl,对象obi可以访问TestClassl中的公有成员函数。TestClass2中定义了一个TestClassl的指针p,给p分配新空间,即指向类TestClassl,输出“T5estClassl”。在TestClass2的构造函数中首先输出“TestClass2”,并在’TestClassl构造函数中输出“TestClassl”。TestClass2析构函数中输出“~TestClass2”,删除指针p,输出“~TestClassl”。析构。TestClassl输出“~TestClassl”。
转载请注明原文地址:https://www.kaotiyun.com/show/lXfp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下类声明:classSAMPLE{intn;public:SAMPLE(inti=0):n(i){}voidsetValue(intn0;};下列关于getVal
有如下类定义:classXX{intxdata;public:XX(intn=0):xdata(n){}};classYY:publicXX{intydata;public:YY(intm=0,intn=0):XX(m),
下列运算符函数中,肯定不属于类Value的成员函数的是()。
下列程序输出的结果是()。#includefun1(chara,charb){charc;c=a;a=b;b=c;}fun2(char*a,charb){charc;c=*a;*a=b;b=c;}f
使用VC6打开考生文件夹下的源程序文件modi3.cpp。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。完成以下功能:(1)声明类objAl,请在注释∥********1********后添加适当的语句。(2)为类0bjA0增加友元函数
下列关于运算符重载的描述中,错误的是
下面是重载为非成员函数的运算符函数原型,其中错误的是()。
下列字符串中,不可以用作C++标识符的是()。
若要重载+、=、<<、==和口运算符,则必须作为类成员重载的运算符是()。
下面不属于软件需求分析阶段主要工作的是()。
随机试题
Schechterisatypically(i)________thefilmversionofStephenKing’shorrornovelTheShiningbecausethequalitiesforwhicht
房水产生于()
疑为垂体腺瘤时,定位诊断首选
A,发热骤起,头痛畏寒,咽喉红肿疼痛,皮肤潮红,痧疹隐隐B,发热渐升,咽红口干,鼻塞流涕,咳嗽频作,皮肤散在丘疹C,恶寒发热,头痛项强,呕吐频繁,时有抽搐,皮肤大块瘀斑D,壮热不解,烦躁口渴,咽喉肿痛,伴有糜烂白腐,皮疹密布,色红
哪几部专著是我国记载药品质量规格、标准的法典( )。
办公楼综合布线系统信息插座的数量,按基本配置标准的要求是:(2006,119)
()是指劳动者为履行劳动给付义务,在用人单位从事工作时间或生产的时间。
网络传输介质的传输速率最高是双绞线。()
沼气:甲烷:气体
马克思主义的基本特征是()。
最新回复
(
0
)