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

admin2018-12-04  19

问题 有如下程序:
    #inc1ude <iostream>
    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 dl(2),d2(3);
    cout<<dl.get()+d2.get()+XA::b<<endl;
    return 0:
    }
    运行时的输出结果是(     )。

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

答案C

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

最新回复(0)