未知题型
有如下程序: #include <iostream> using namespace std; class Obj { static int i; public: Obj( ){i++;} ~Obj(){i--;} static int getVal( ){ return i;} }; int Obj::i=0; void f() {Obj ob2; cout<<ob2.getVal( ); } int main( ){ Obj ob1; f(); Obj *ob3=ew Obj; cout<<ob3->getVal( ); delete ob3; cout<<Obj::getVal( ); return 0; } 程序的输出结果是
A.232
B.231
C.222
D.221
- A.getVal(
B.232
B.231
C.222
【参考答案】
D
解析:本题主要考查的是静态成员。静态成员的特性是不管这个类创建了多少个对象,它的静态成员都只有一个拷贝(副本......
(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)
点击查看答案
相关考题
-
未知题型
有如下程序 #include <iostream> using namespace std; class Base { protected: Base( ){cout<<'A'; } Base(char c) { cout<<c; } }; class Derived: public Base { public: Derived(char c){ cout<<c; } }; int main( ){ Derived d1 ('B'); return 0; } 执行这个程序屏幕上将显示输出D.BB
A.B
B.BA
C.AB -
未知题型
有如下类定义: class MyBase { int k; public: MyBase(int n=0):k(n) { } int value( )const{ return k;} }; class MyDerived: MyBase { intj; public: MyDerived(int i): j(i) {} int getK( )const{ return k; } int getJ( )const{ return j; } }; 编译时发现有一处语法错误,对这个错误最准确的描述是D.类MyDerived的构造函数没有对基类数据成员k进行初始化
A.函数getK试图访问基类的私有成员变量k
B.在类MyDerived的定义中,基类名MyBase前缺少关键字public、protected或private
C.类MyDerived缺少一个无参的构造函数 -
判断题
1.神经症是一种持久的心理冲突,当事人能够感觉到这种冲突并感到痛苦,同时其心理功能和社会功能也受到了影响。 正确 错误
