ostream& operator <<(ostream& osObject, const storageRentals& rentals)
{
osObject << rentals.summaryReport();
return osObject;
}
summaryReport() is a void function, and it is giving me an error:
no operator “<<” matches these operands
but the error is not there if I change the summaryReport function to an int, but the problem I have with that is you have to return a value, and it is printing it out on the screen.
void storageRentals::summaryReport() const
{
for (int count = 0; count < 8; count++)
cout << "Unit: " << count + 1 << " " << stoUnits[count] << endl;
}
Is there any way to overload cout << with a void function?
You should define
summartReporttakingostream&as parameter, as shown here:then call it as:
By the way, it is not called “overloading cout”. You should say, “overloading
operator<<forstd::ostream.