首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class Person{ public: Person(string
有如下程序: #include #include using namespace std; class Person{ public: Person(string
admin
2020-06-29
32
问题
有如下程序:
#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/Ezyp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下程序:#includeusingnamespacestd;classTV{public:TV(ints=41):size(s){}
下列函数声明中,错误的是
有如下类定义:classCup{public:voidSetPrice(doubleval=5.8);doubleGetPrice(){returnprice;
有如下类声明:classTe{public:Te();//①Tete;//②Te*
有如下类声明和函数声明:classBase{intm;public:intn;protected:intp;};classDe
有如下程序:#include#includeusingnamespacestd;classPerson{public:Person(string
在C++中,编译系统自动为一个类生成默认构造函数的条件是
请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程proj1,此工程中含有—个源程序文件proj1.cpp。其中位于WI"注释“//ERROR**********found**********”之后的一行语句存在错误。请改正这些错误,使程序的输
下列字符中,可以出现在合法的C++标识符中的是
在下列枚举符号中,用来定位文件开始位置的方式是
随机试题
滤过灭菌法中常用的滤膜孔径是
某女,32岁。妊娠四个月后自述经常出现胎动不安,并伴有虚劳咳嗽症状。中医处以山东阿胶膏进行治疗。该药物组成为阿胶、党参、白术、黄芪、枸杞子、白芍、甘草。新阿胶的原料为()
对厌氧菌有广谱作用的药物是
场景甲机电公司承接某新建油库的球罐现场组装焊接工程,要求采用散装法施工。机电公司编制了施工设计和球罐现场组装方案,经总工程师批准开始施工,工程按方案进展的很顺利。球罐安装完毕,进行充水试验,发现罐壁不严密,而且产品焊接试板和球罐焊后几何尺寸也不符合要求。
某行政机关将办公大楼的建设工程发包给某建筑公司承建,行政机关与建筑公司建立的是( )。
下列对气质的描述错误的是()。
在数据管理技术的发展过程中,可实现数据共享的是
Whatmakesbasketballthemost______ofsportsishowthesestylesdonotnecessarilyclash.
ImpactofUrbanizationTheeffectsofurbanization:Example:intheU.S.only【L31】________oflandbuiltonlossof【L32】________
DearProf.Smith,Thankssomuchforyourwarmwelcomeandkindhospitalityyoushowedmeduringmyrecentvisittoyouruni
最新回复
(
0
)