首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include #include using namespace std; class MyBag{ public: MyBag(string br,string cr):brand(br),
有如下程序: #include #include using namespace std; class MyBag{ public: MyBag(string br,string cr):brand(br),
admin
2019-03-05
50
问题
有如下程序:
#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 main(){
MyBag one("CityLife","Gray"),two("Micky","Red");
cout<
return 0;
}
若程序运行时的输出结果为2,则横线处缺失的语句是( )。
选项
A、int count=0;
B、static int count:0;
C、int MyBag::count=0;
D、static int MyBag::count=0;
答案
C
解析
本题考查构造函数和析构函数,以及静态数据成员,题目中要求输出2,那么定义两个对象时,就执行构造函数,使得静态数据成员++count,得到2,那么count初始化就应该为0,静态数据成员初始化时,只能在类体外进行初始化,一般形式为:
数据类型类型::静态数据成员名=初值
因此本题选C。
转载请注明原文地址:https://kaotiyun.com/show/9vAp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
在下面横线上填上适当的语句,完成程序。#include<iostream>usingnamespacestd;classBase{intx:
下列程序的输出结果是______。#include<iostream.h>#include<cstring.h>usingnamespacestd;voidfun(constchar*s,char&C){c=s[strlen(
有如下程序:#include<iostream>usingnamespacestd;classpoint{intx,y;public:point(intvx,intvy){x=vx;
以下程序的输出结果是#include<iostream>usingnamespacestd;intmain(){cout.fill(’*’);cout.width(5);cous<<hex<<100<<end1;re
如果算符函数调用格式的表达式:x.operator-(operator++(y,0)中的“—”是作为成员函数重载的,“++”是作为友元函数重载的,那么该表达式还可以表示为:()
以下函数实现的功能是voidfun(char*s){char*p,*q,temp;p=s;q=s+strlen(s)-1;while(p<q){temp=*p;*p=*q;
以下叙述正确的是
C++语言程序的注释可以出现在程序中的任何地方,一个注释以______作为开始和结束的标记。
下列选项中,作为是数据库系统的核心的是()。
随机试题
青霉素在磷酸盐缓冲液中降解属于
下列有关胺碘酮的叙述不正确的是
根据以下资料,回答106-110题2008年,我国境内民用航空通航机场共有158个(不含香港和澳门,下同),其中定期航班通航机场152个。定期航班通航城市150个。2008年,全国各机场共完成旅客吞吐量40576.2万人次,比上年增长4.70%。
中秋节:月饼:团圆
作者举“推敲”为例,要说明什么?下面说法正确的一项是:这段文字在思路上十分严谨,下面对本段写作思路的表述不够准确的一项是:
Imagineaworldinwhichweareassignedanumberthatindicateshowinfluentialweare.Thisnumberwouldhelpdetermine【C1】___
PanicApanicisaformofcollectiveinwhichagroupofpeople,facewithanimmediatethreat,reactinanuncoordinateda
InwhichcitydoesMr.Hoodwork?
Sheseldomgoesshoppingonweekends,______.
Teachingisahighly-complexoccupation.Ithasbeendescribedintermsofverydifferenttypesofroles.Forexample,teachers
最新回复
(
0
)