首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class MyBag{ public: MyBag(string b
有如下程序: #include #include using namespace std; class MyBag{ public: MyBag(string b
admin
2020-05-14
10
问题
有如下程序:
#include
#include
using namespace std;
class MyBag{
public:
MyBag(string br,string cr):brand(br),color(cr) { ++count; }
~MyBag() { --count; }
static int GetCount() { return count; }
private:
string brand,color;
static int count;
};
int MyBag::count=0;
int main(){
MyBag one("CityLife","Gray"),two("Micky","Red");
_____________________
return 0;
}
若程序运行时的输出结果为2,则横线处缺失的语句不可能是
选项
A、cout<
B、cout<
C、cout<
D、cout<
答案
B
解析
本题考查静态数据成员和静态成员函数,静态成员函数只能使用本类中的静态数据成员,且静态成员函数不归属任何一个对象,而是属于类,题目中要求输出2,那么就要将count输出,题目中定义了两个对象,都对count进行了++,所以调用静态成员函数直接使用类名,B选项正确。
转载请注明原文地址:https://kaotiyun.com/show/Ov8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下面是“二维向量”vector2D的定义,其中作为成员函数重载的运算符“+”的功能是将两向量的分量x和y对应相加,然后返回作为相加结果的新对象。那么应该在横线上填入的语句是()。classvector2D{private
有如下数组声明:intnum[10];,下标值引用错误的是
以下内容不属于算法程序所占的存储空间的是()。
派生类对象对其基类中的什么成员是可访问的?
有如下定义:intb[10]={1,2,3,4,5,6,7,8,9,10},*q=b;则数值为8的表达式是()。
数据库系统的核心是
在C++中,动态创建对象可以使用【 】操作符来完成。
如果表达式x=y*z中的“*”是作为成员函数重的运算符,采用运算符函数调用格式,该表达式还可以表示为______。
有如下程序:#include<iostream>usingnamespacestd;classCon{charID;public:Con():ID(’A’){cout<<1;}Co
已知在函数func()中语句this->ff=0;与语句fi=O;的效果完全相同。对于这一现象,下列表述中错误的是()。
随机试题
国际上,强制性的工程保险不包括()。
变紧,拧紧v.t______
按照组织所处的经营环境状况不同,组织变革可以分为()
运用PDCA循环的护理管理方法,对护理质量持续改进,其中“D”代表的含义是
曲面x2+y2+z2=2z之内以及曲面z=x2+y2之外所围成的立体的体积V等于()。
阅读下面材料,回答问题。民警罗某于2013年1月3日中午巡逻下班后开着警车回家,因无处停车,就将警车停靠在自家小区附近的禁停路段,后被某市民悄悄贴上手写的“违法行为告知书”.样式非常类似于交警开具的罚单。网民张某用照相机将这一幕拍下来,并上传到微博,引起
A.FⅢB.FⅦC.FⅧD.FⅩE.FⅫ外源性凝血途径的始动因子是
犯罪的主观方面是指()。
土地革命战争时期,中国的红色政权能够存在与发展的客观条件有()
午後の会議にはだれが出席しても構わないが、君が出てくれるなら、それに______。
最新回复
(
0
)