单选题
有如下程序:
#include<iostream>
Using namespace std;
Class Amount{
int amount;
public;
Amount(int n=0):amount(n){}
Int getAmount()const{return amount;}
Amount &operator+=(Amount a){
amount+=a.amount;
return ;
}
};
int main(){
Amount x(3),y(7);
x+=y;
cout<<x.getAmount()<<endl;
return 0;
}
已知程序的运行结果是10,则下划线处缺失的表达式是______。
【正确答案】
A
【答案解析】[解析] 此题考查的是“+”运算符重载和this指针。语句amount+=a.amount;实现3和7的求和得到amount=10,要使程序的输出结果为10,又因为函数的返回值类型为Amount&,所以横线处填入*this。