有如下程序: #include<iostream> using namespace std; class XA { int a; public: static intb: XA(int aa):a

admin2020-07-30  9

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

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

答案C

解析 执行XA类的实例变量d1(2)时,成员函数d1.get()的返回值等于2,XA.b的值等于1,执行XA类的实例变量d2(3)时,成员函数d1.get()的返回值等于3,XA.b的值等于2,所以输出结果为2+3+2=7。
转载请注明原文地址:https://kaotiyun.com/show/LDyp777K
0

最新回复(0)