我无法弄清楚我正在阅读的书的以下部分实际上是做什么的。
//this function supposed to mimic the += operator
Sales_data& Sales_data::combine(const Sales_data &rhs)
{
units_sold += rhs.units_sold; // add the members of rhs into
revenue += rhs.revenue; // the members of ''this'' object
return *this; // return the object on which the function was called
}
int main()
{
//...sth sth
Sales_data total, trans;
//assuming both total and trans were also defined...
total.combine(trans);
//and here the book says:
//we do need to use this to access the object as a whole.
//Here the return statement dereferences this to obtain the object on which the
//function is executing. That is, for the call above, we return a reference to total.
//*** what does it mean "we return a reference to total" !?
}
我应该说我以前对 C# 有一点了解,并且不太了解究竟是如何return *this;
影响整个对象的。