首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include<iostream> #include<string> using namespace std; class MyBag{ public: MyBag(string br,str
有如下程序: #include<iostream> #include<string> using namespace std; class MyBag{ public: MyBag(string br,str
admin
2019-05-22
22
问题
有如下程序:
#include<iostream>
#include<string>
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(”CityLifeIl,”Gray”),two(”Micky”,”Red”);
cout<<MyBag::GetCount();
return 0;
}
若程序运行时的输出结果为2,则横线处缺失的语句是( )。
选项
A、int count=0;
B、smile int count=0;
C、int MyBag::count=0;
D、stailc int MyBag::count=0;
答案
C
解析
本题考查构造函数和析构函数,以及静态数据成员,题目中要求输出2,那么定义两个对象时,就执行构造函数,使得静态数据成员++count,得到2,那么count初始化就应该为0,静态数据成员初始化时,只能在类体外进行初始化,一般形式为:
数据类型类型::静态数据成员名=初值
因此本题选C。
转载请注明原文地址:https://kaotiyun.com/show/Kb8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列叙述中错误的是()。
设有表示学生选课的3张表:学生S(学号,姓名,性别,年龄,身份证号),课程C(课号,课名),选课SC(学号,课号,成绩),则表SC的关键字(键或码)为
A、 B、 C、 D、 B因为对象a被定义为常对象,所以a.disp()语句调用的是类的常成员函数voiddispoconst,输出的结果是disp2。
A、 B、 C、 D、 Awhile循环取串长度,赋值给j,然后在for循环中由串两边开始向中间进行字符比较,当最后i和j标识字符位置的变量相等,那么奇数个字符,或者i大于j时那么偶数个字符,则表示是对称的。
A、 B、 C、 D、 B数据流图中带箭头的线段表示数据流,沿箭头方向传递数据的通道,一般在旁边标注数据流名。
构造函数构造函数的主要作用是对数据成员初始化,系统为成员分配内存时,保留这些存储单元的原状。
2首先声明为private的“private:intj;”中j为私有成员。然后在类中没有指定,系统默认为私有。即“inti:”中的i也是私有成员。所以本题中的私有成员数量为2。
A、 B、 C、 D、 B只有在创建对象时才会调用类的构造函数,在定义指针时不会调用构造函数,本程序共生成了3个同类对象a,b[2]。
针对数组定义intdata[10];,下列叙述中错误的是A)用*data可访问到数组的首元素B)用data[9]可访问到数组的末元素C)用data[10]访问数组元素会超出数组的边界D)data共有10个元素,其首元素是data[1]
随机试题
下列叙述正确的是________________。
下列各种青霉素中不具有广谱抗菌作用的是
霍乱主要经()流脑主要经()
滴虫性阴道炎的治愈标准是
某有限责任公司的股东甲、乙都想转让其股份,甲直接将股份转让给了同为该有限责任公司的丙,乙欲将股份转让给该有限责任公司股东以外的丁,但有限责任公司的另一股东戊得知后也想以同样的价格购买乙的股份,但乙以其已与丁达成协议拒绝了戊的要求。2000年9月10日,该公
拓展型课程适合用于下列哪种情况()
不随意注意是指事先没有预定的目的,也无需作任何意志努力,不由自主地对某些事物发生的注意。又叫无意注意,是注意的一种初级表现形式。根据上述定义,下列属于不随意注意的是()。
否认思维和存在具有同一性的哲学是()。
Bankingandfinancialsystemsfilledwith______andcorruptionhindertheregion’ssuccess.
RelationshipTalkingPoints:SpeakYourSpouse’sLanguageA)AnnaandMikePetersonrecentlyhaddinnerattheirfavouritesteakh
最新回复
(
0
)