问题 单项选择题

有下列程序:
#include<iostream>
Using namespace std;
Class Amount
int amount;
public;
Amount(int n=O):amount(n)
Int getAmount()constreturn 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

B.this

C.&amount

D.amount

答案

参考答案:D

解析: 此题考查的是“+”运算符重载和this指针。语句amount+=a.amount;实现3和7的求和,得到amount=10,要使程序的输出结果为10,需要把amount的值作为函数的返回值,所以横线处应填入amot。

单项选择题 A2型题
单项选择题