有如下程序: #include using namespace std; class XA { int a; public: s

admin2015-07-22  32

问题 有如下程序:
        #include
        using namespace std;
        class XA {
                int a;
        public:
                static int b;
                XA(int aa):a(aa) {b++;}
                ~XA() {}
                int get() {return a;}
        };
        int XA::b=0;
        int main() {
                XA d1(2),d2(3);
                cout<                return 0;
        }
运行时的输出结果是

选项 A、5
B、6
C、7
D、8

答案B

解析 本题考查类的静态数据成员,题目中定义了类的静态数据成员b,当执行定义两个对象时执行构造函数,构造函数执行b++,所以b最终为2,而d1.get()为2,d2.get()为3,最终结果为7,C选项正确。
转载请注明原文地址:https://kaotiyun.com/show/6uNp777K
0

最新回复(0)