首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Person{ public: Person(string
有如下程序: #include #include using namespace std; class Person{ public: Person(string
admin
2020-07-23
49
问题
有如下程序:
#include
#include
using namespace std;
class Person{
public:
Person(string n):name(n) { }
~Person() { cout<<’P’; }
private:
string name;
};
class Date{
public:
Date(int y=2012,int m=12,int d=21):year(y),month(m),day(d) { }
~Date() { cout<<’D’; }
private:
int year,month,day;
};
class Student:public Person{
public:
Student(string n,int y,int m,int d,char c)
:birthday(y,m,d),sex(c),Person(n) { }
~Student() { cout<<’S’; }
private:
Date birthday;
char sex;
};
int main(){
Student stu1("Zhang",1990,10,1,’F’);
return 0;
}
运行时的输出结果是
选项
A、S
B、SP
C、SPD
D、SDP
答案
D
解析
本题考查派生类的析构函数,派生类的析构函数执行顺序为先构造的后析构,后构造的先析构,所以执行Studentstu1("Zhang",1990,10,1,’F’);时,依次执行person、Date、Student构造函数,然后依次执行Student、Date、person的析构函数,所以输出为SDP,D选项正确。
转载请注明原文地址:https://kaotiyun.com/show/Cnyp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序段:inti=1;intj=4;intmain(){intj=i,i=8;cout
下列有关函数重载的叙述中,错误的是()。
有如下程序:#include#includeusingstd::cout;classPoint{public:frienddoubledi
除了显式定义的构造函数外,类中还有可能包含编译器自动生成的构造函数,因此一个类所拥有的构造函数的至少有
有如下类声明:classMau{intk;constintm;public:Mau(intk1,intm1);};则构造函数Mau的下列定义
下列关于运算符重载的叙述中,错误的是()。
若实体A和B是一对多的联系,实体B和C是一对一的联系,则实体A和C的联系是
下列枚举类型的定义中,包含枚举值5的是
已知表达式--a中的"--"是作为成员函数重载的运算符,则与--a等效的运算符函数调用形式为
在E-R图中,用来表示实体联系的图形是()。
随机试题
A.白前B.百部C.前胡D.芥子E.桔梗性微寒,既降气祛痰,又宜散风热的药是()。
生活用水应由()开支或职工自行负担。
关于改性沥青混合料施工摊铺和压实温度的说法,正确的是()。
属于化学教学综合方法的是()。
乳牙与恒牙如何鉴别?
群英和志城都是经营微型计算机的公司,它们是电子一条街的两颗高科技新星。为了在微型计算机方面与国际大公司较量,群英公司和志城公司在加强管理、降低成本、提高质量和改善服务几方面采取了有效的措施。两家公司2002年的微机销量比2001年分别增加了15万台和12万
Withincreasingprosperity,WesternEuropeanyouthishavingaflingthatiscreatingdistinctiveconsumerandculturalpatterns
ItwasabeautifulsummerdayandIwastakingawalkinthedowntownareaofMadrid.WhenIturnedastreet【C1】______Iheardth
Completethetablebelow.WriteNOMORETHANONEWORDforeachanswer.
ActivitiesProgrammeTIMEANDPLACEJanuary24-30Jan.24-30,8:00a.m.~5:00p.m.Jan.25-29,12:00p.m.~9:00p.m.Classro
最新回复
(
0
)