static int b; const int c; };
int Test::b = 0;
在标注号码的行中,能被正确编译的是 A)① B)② C)③ D)④ (30)有如下程序: #include
A() { cout << \ ~A() { cout << \ };
class B : public A { A* p; public:
B() { cout << \ p = new A(); }
~B() { cout << \ delete p; } }; int main() {
B obj; return 0; }
执行这个程序的输出结果是 A)BAA~A~B~A B)ABA~B~A~A C)BAA~B~A~A D)ABA ~A~B~A (32)有如下程序: #include
public:
void fun1() { cout << \ virtual void fun2() { cout \ };
class Derived : public Base {
<< public:
void fun1() { cout << \ void fun2() { cout << \ };
void f(Base& b) { b.fun1(); b.fun2(); } int main() {
Derived obj; f(obj); return 0; }
执行这个程序的输出结果是 A) B) Base Base Base Derived C) D) Derived Derived Base Derived (33)有如下程序: #include
class Complex {
double re, im; public:
Complex(double r, double i) : re(r), im(i) { }
double real() const { return re; } double image() const { return im; } Complex& operator += (Complex a) {
re += a.re; im += a.im; return *this; } };
ostream& operator << (ostream& s, const Complex& z) { return
s<<'('< int main() { Complex x(1,-2), y(2,3); cout << (x+=y) << endl; return 0; } 执行这个程序的输出结果是 A)(1,-2) B)(2,3) C)(3,5) D)(3,1) (35)有如下类声明: class SAMPLE { int n; public: SAMPLE(int i=0):n(i){} void setValue(int n0); }; 下列关于 getValue 成员函数的实现中,正确的是 A) SAMPLE::setValue(int n0){ n=n0;} B)void SAMPLE::setValue(int n0){ n=n0;}