Function returning "This" object in C++

Viewed 765

So, following is a member function of Class Sales_data which is defined outside the class,

Sales_data& Sales_data::combine(const Sales_data &rhs) {
    units_sold += rhs.units_sold;
    revenue += rhs.revenue; //adding the members of rhs into the members of "this" object
    return *this;
} //units_sold and revenue are both data members of class

When the function is called, it is called like

total.combine(trans); //total and trans are the objects of class

What i am not understanding is the function returning *this, i understand it returns an instance of the object but it is not returning that instance to anything as we can see during function call, also if i don't write the return statement, would it work any differently.

Someone please explain elaborately because i am just not getting it.

3 Answers
Related