首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下类声明: class Base1{ }; class Base2{ }; class Derived: public Base2,public Base1{ }; 在一个 Derived 对象消亡时,析构函数被调用的顺序
有如下类声明: class Base1{ }; class Base2{ }; class Derived: public Base2,public Base1{ }; 在一个 Derived 对象消亡时,析构函数被调用的顺序
admin
2020-07-23
94
问题
有如下类声明:
class Base1{ };
class Base2{ };
class Derived: public Base2,public Base1{ };
在一个 Derived 对象消亡时,析构函数被调用的顺序是
选项
A、~Derived、~Base1、~Base2
B、~Derived、~Base1、~Base2
C、~Base1、~Base2、~Derived
D、~Base2、~Base1、~Derived
答案
A
解析
C++中,派生类构造函数都是先调用基类构造函数,再根据声明次序定义数据成员,另外对于多继承,派生类的构造函数初始化列表中,基类构造函数是按照基类在派生类的派生列表中出现的次序调用的;而析构函数是按构造函数运行顺序的逆序进行调用的,可知题目中析构函数的调用顺序为:派生类Derived的析构函数,Base1的析构函数,Base2的析构函数;答案为A。
转载请注明原文地址:https://kaotiyun.com/show/GFyp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序:#includeusingnamespacestd;classCup{public:Cup(doubleval=5.8):price(val){
有如下类定义:classXX{intxdata;public:XX(intn=0):xdata(n){}};classYY:p
一间宿舍可住多个学生,则实体宿舍和学生之间的联系是( )。
下列关于运算符重载的叙述中正确的是
若要对Data类中重载的加法运算符成员函数进行声明,下列选项中正确的是()。
有如下程序:#include#includeusingnamespacestd;classInstrument{public:Instrument
下列语句中,错误的是()。
T列符号中能够作为C++标识符的是()。
下列选项中,与实现运行时多态性无关的概念是()。
若有如下类声明classMyClass{public:MyClass(){cout<<1;}};执行下列语句MyClassa,b[2],*p1[]2:以后,程序的输出结果是()。
随机试题
毛泽东同志曾经指出,文章和文件都应当具有三种性质,这三种性质是
宁能知人之卒不救,弃城而逆遁逆遁:
求幂级数的收敛域.
Inthepast,Americanfamilies【36】tobequitelarge.Parents【37】fiveormorechildrenwerecommon.Overtheyears,the【38】ofthe
胸壁肿瘤
最容易发生肩关节脱位的是
股权投资行业主要用到的估值方法为相对估值和()。
在面向对象的程序设计中,类描述的是具有相似性质的一组______。
MakeTheseHousesYourHomeIfyouarenotsureyoucanaffordanewhome,butyou’vealwayswantedone,nowyoucanstoprentin
Thispartistotestyourabilitytodopracticalwriting.YouarerequiredtocompletetheEmploymentApplicationformaccordin
最新回复
(
0
)