lundi 20 mars 2023

What is the use of *this in combine function given below

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
}

I saw above method somewhere, and I am confused why *this pointer is being returned? even though without it (using void return type) function does the same thing. I am not an expert in C++, so can any one explain what am I missing?

Aucun commentaire:

Enregistrer un commentaire