有如下程序: #include using namespace std; class XA{ int a; public: static int b: XA(int aa):a(aa){b++;)

admin2014-08-29  31

问题 有如下程序:
    #include
    using namespace std;
    class XA{
    int a;
    public:
    static int b:
    XA(int aa):a(aa){b++;)
    ~XA(){}
    int get0{return a;}
);   
    int XA::b=0;
    int main()    {
    XA d1(2),d2(3);
    cout<    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/PWNp777K
0

最新回复(0)