首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include using namespace std; class XB { int a; public: s
有如下程序: #include using namespace std; class XB { int a; public: s
admin
2020-10-21
25
问题
有如下程序:
#include
using namespace std;
class XB {
int a;
public:
static int b;
XB(int aa):a(aa) { b++; }
~XB() { b--; }
int get() {return a;}
};
int XB::b=0;
int main() {
XB d(2);
int n=d.get()+XB(3).get();
cout<
return 0;
}
运行时的输出结果是
选项
A、5
B、6
C、7
D、8
答案
B
解析
本题考查类的构造函数和静态数据成员,题目中定义了类的静态数据成员b,当执行定义对象d(2)和XB(3).get()时执行构造函数,构造函数执行b++,所以b最终为2,而d.get()为2,最终结果为6,B选项正确。
转载请注明原文地址:https://kaotiyun.com/show/pVyp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有3个关系R、S和T如下:则由关系R和S得到关系T的操作是()。
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main•cpp,其中有坐标点类point、线段类Line和三角形类Triangle的定义,还有main函数的定义。程序中两点间距离的计算是按公式实现的,三角
下列有关运算符重载的叙述中,正确的是()。
下列叙述中正确的是()。
使用VC6打开考生文件夹下的源程序文件modi1.cpp,使它能得出正确的结果。本程序要求屏幕输出:n=99注意:不要改动main函数,不能增行或删行,也不能更改程序的结构,错误的语句在//********error********的下面。#inc
使用VC6打开考生文件夹下的源程序文件modi1.cpp,该程序运行时有错误,请改正其中的错误,使程序正确运行。并且使程序输出的结果为:OK注意:错误的语句在//******error******的下面,修改该语句即可。#include<iostre
关于在调用模板函数时模板实参的使用,下列表述正确的是()。
已知函数模板定义如下:templateTmin(Tx,TY){returnx
随机试题
在1954年出版的《管理的实践》一书中提出目标管理概念的管理学家是()。
脾梗死灶切面的肉眼形状常为
治疗老年性骨质疏松症可选择的药品有()。
鼓轮大半径为R,小半径为r,轮轴整体对水平轴O的转动惯量为J0,连接在轮轴上的弹簧刚度系数为k,用绳索系在轮轴上的物块质量为m,如图所示。则该系统自由振动的固有频率ωn为()。
断裂构造主要分为哪两大类?①节理;②断层;③向斜;④背斜。
某货轮装载一批进口货物于2006年4月20日(星期四)申报进境,则该批货物至迟应于( )向海关申报。
某酒厂2009年2月份,研发生产一种新型粮食白酒,第一批1000公斤,成本为17万元,作为礼品赠送,无同类售价;第二批500公斤,作为广告样品供客户品尝,成本为4万元,没有同类售价。已知粮食白酒的成本利润率10%,则该月应纳消费税为()。
利用校园的文化墙和黑板报来影响学生的品德,这种德育方法是()。
线性表(a1,a2,a3,…,an)中元素递增有序且按顺序存储于计算机内。要求设计一算法用最少时间在表中查找数值为x的元素,并将其与后继元素位置相交换。如果线性表中找不到该元素,则将该元素插入表中并使表中元素仍递增有序。分别给出算法各部分的时间复杂度。
A、Thetripwasworththetimebutnotthemoney.B、Thetripwasworththemoneybutnotthetime.C、Thetripwasawasteoftime
最新回复
(
0
)