题目内容

有如下类声明: class SAMPLE { int n; public : SAMPLE ( int i = 0 ):n(i){ } void setValue ( int n0); }; 下列关于setValue 成员函数的实现中,正确的是( )。

A. void SAMPLE::setValue (int n0){n=n0;}
B. SAMPLE::setValue(int n0){n=n0;}
C. void setValue(int n0){n=n0;}
D. setValue(int n0){n=n0;}

查看答案
更多问题

若有以下类W说明,函数fConst的正确定义是( )。 class W { int a; public: void fConst(int) const ; };

A. void W::fConst(int k)const { k=a; }
B. void W::fConst(int k)const { k=a++; }
C. void W::fConst(int k)const { cin>>a; }
D. void W::fConst(int k)const { a=k; }

若有以下说明,在类外使用对象objX成员的正确语句是( )。 class X { int a; void fun1(); public: void fun2(); }; X objX ;

A. objX.fun2();
B. objX.a=0;
C. objX.fun1();
D. X::fun1();

类的构造函数在以下什么情况下会被自动调用( )

A. 定义对象时
B. 定义成员函数时
C. 定义数据成员时
D. 定义友元函数时

有如下程序: #includeusing namespace std; class MyClass{ public: MyClass(int i=0){cout<<1;} MyClass(const MyClass&x){cout<<2;} MyClass& operator =(const MyClass&x){cout<<3;return *this;} ~MyClass(){cout<<4;} }; int main(){ MyClass obj1(1),obj2(2),obj3(obj1); return 0; } 运行时的输出结果是( )。

A. 112444
B. 11114444
C. 121444
D. 11314444

答案查题题库