首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下类定义: class Test { public: Test() { a = 0; c = 0; } // ① int f(int a) const { this->a = a; } // ② static int
有如下类定义: class Test { public: Test() { a = 0; c = 0; } // ① int f(int a) const { this->a = a; } // ② static int
admin
2020-06-29
64
问题
有如下类定义:
class Test
{
public:
Test() { a = 0; c = 0; } // ①
int f(int a) const { this->a = a; } // ②
static int g() { return a; } // ③
void h(int b) { Test::b = b; }; // ④
private:
int a;
static int b;
const int c;
};
int Test::b = 0;
在标注号码的行中,能被正确编译的是( )。
选项
A、①
B、②
C、③
D、④
答案
D
解析
只能通过构造函数的参数初始化列表对常数据成员进行初始化,本题中常数据成员为c。①通过默认构造函数初始化c,所以不正确。常成员函数只能引用本类中数据成员,而不能修改它,所以②不正确。静态成员函数由于没有this指针,所以不能访问本类中的非静态成员,所以③错误。
转载请注明原文地址:https://www.kaotiyun.com/show/We8p777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列不属于结构化分析的常用工具的是
下面程序的运行结果为#include<iostream.h>classA{staticintn;public:A(){n=1;}A(intnum){n=num;}
静态成员函数没有
模板对类型的参数化提供了很好的支持,因此
表达式x.operator+(y.operator++(0))还可以写成【】。
下述关于数据库系统的叙述中正确的是
下列有关模板的叙述中,正确的是()。
下列有关运算符重载的表述中,正确的是
下列有关运算符重载的表述中,正确的是
随机试题
RaisingWiseConsumers[A]Almostanyonewithaprofitmotiveismarketingtoinnocents.Helpyourkidsunderstandit’sOK
进行分区划线分离细菌,操作错误的是
氨基酸进入肠黏膜上皮细胞是属于
充分体现人与自然统一的整体运动观念,确立了因时、因地、因人制宜的辨证施治原则的医学书籍是
设计工作中的方案设计、初步设计、技术设计、施工图设计之间的关系属于()。
金融市场可分为有形市场和无形市场。两个市场最明显的区别是()。
A、 B、 C、 D、 B
ThehumanspeciescameintobeingatthetimeofthegreatestbiologicaldiversityinthehistoryoftheEarth.Today,ashuman
A、Theirworkcanonlybeusedasamodel.B、Mostoftheirwritersarepoorlypaid.C、Mostwritershaveadoctorate.D、Studentsm
Itseemsyoualwaysforget—yourreadingglasseswhenyouarerushingtowork,yourcoatwhenyouaregoingtothe【C1】______,you
最新回复
(
0
)