有如下程序: #inc1ude<iostream> Using namespace std; Class Amount{ int amount; public; Amount(int n=0): amoun

admin2019-06-12  15

问题 有如下程序:
    #inc1ude<iostream>
    Using namespace std;
    Class Amount{
    int amount;
    public;
    Amount(int n=0):  amount(n){}
    Int getAmount()const {retum amount;}
    Amount &operator+=(Amount a){
    amount+=a.amount;
    retum ;
        }
    };
    int main(){
    Amount x(3),y(7);
    x+=y;
    cout<<x.getAmount()<<end1;
    retum 0;
    }
    已知程序的运行结果是10,则下划线处缺失的表达式是(    )。

选项 A、*this
B、this
C、&amount
D、amount

答案A

解析 此题考查的是“+”运算符重载和this指针。语句amount+=a.amount;实现3和7的求和得到amount=10,要使程序的输出结果为10,又因为函数的返回值类型为Amount&,所以横线处填入*this。
转载请注明原文地址:https://kaotiyun.com/show/IL8p777K
0

最新回复(0)