首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下类定义: class Test { public: Test(){a=0;c=0;}//① int f(int a)const{this一>a=a;}//② static int g(){return
有如下类定义: class Test { public: Test(){a=0;c=0;}//① int f(int a)const{this一>a=a;}//② static int g(){return
admin
2019-05-22
17
问题
有如下类定义:
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://jikaoti.com/ti/irA0FFFM
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有如下类声明:classTestClass{inti;private:intj;protected:intk;public:intm,n;};其中,私有成员的数量为______。
请将下列栈类Stack补充完整。classStack{private:intpList[100];//int数组,用于存储占的元素inttop;//栈顶元素(数组下标)public:
请将如下程序补充完整,使得输出结果为:bbaa。#include<iostream>usingnaluespacestd;classA{public:______{eout<<"aa";}}
已知类sample是一个抽象类,其成员函数display是无形参、无返回类型的纯虚函数,请完成其声明:sample{public:sample(){};______};
已知函数f的原型是voidf(int*a,long&B);,变量v1、v2的定义是:intv1:longv2:下列调用语句中正确的是
A、 B、 C、 D、 C因为staticvoidchange()为静态函数,静态函数主要访问静态数据,不访问非静态数据。所以函数中访问了数据y,所以下划线的数据类型应对应为static。
A、 B、 C、 D、 BPoint&operator++(){x++;return*this;}是在成员函数运算符重载单目运算符(前缀方式),Pointoperator++(int){Poin
A、 B、 C、 D、 C在数据字典编制过程中,常使用定义方式描述数据结构。
下列叙述中正确的是A)软件测试的主要目的是发现程序中的错误B)软件测试的主要目的是确定程序中错误的位置C)为了提高软件测试的效率,最好由程序编制者自己来完成软件测试的工作D)软件测试是证明软件没有错误
随机试题
在“教师”表中,若查找“职工编号”是“T00001”或“T00002”的记录,应在查询设计视图的“条件”行中输入()。
A、ThePCmarkethaspickeduprapidlyinthepastmonths.B、PCsaresoldatlowerpricesduringtheshoppingseason.C、PCshipme
计算由y2=9一x,直线x=2及y=一1所围成的平面图形上面部分(面积大的那部分)的面积A
患者身大热,汗大出,口大渴,面赤,气粗似喘,心烦躁扰,舌苔黄燥,脉洪大,该症状为
在采暖地区的配变电所中,下列哪个房间需要设采暖装置?
施工方项目管理的目标不包括( )。
已知|a—3.25|+=0,则a、b、c从小到大排列的顺序为__________.
荀子认为,人的知识、智慧、品德等,都是由后天学习、积累而来的,他专门写了《劝学》篇,论述学习的重要性,肯定人是教育和环境的产物,倡导____________、日积月累、不断求知的学习精神。填入画横线部分最恰当的一项是()。
把下面的六个图形分为两类,使每一类图形都有各自的共同特征或规律,分类正确的一项是:
Sinceitsfoundationin1954,theUnitedNationshaswrittenintoitsmajorcovenantstheneedtoestablishminimumagesforma
最新回复
(
0
)