单选题
有如下程序: #include
using namespace std; class XB { int a; public: static int b; XB(int aa):a(aa) { b++; } ~XB() { b--; } int get() {return a;} }; int XB::b=0; int main() { XB d(2); int n=d.get()+XB(3).get(); cout<
A、
5
B、
6
C、
7
D、
8
【正确答案】
B
【答案解析】
解析:本题考查类的构造函数和静态数据成员,题目中定义了类的静态数据成员b,当执行定义对象d(2)和XB(3).get()时执行构造函数,构造函数执行b++,所以b最终为2,而d.get()为2,最终结果为6,B选项正确。
提交答案
关闭