Überlastung << operator für std::ostream

ostream& operator <<(ostream& osObject, const storageRentals& rentals)
{
    osObject << rentals.summaryReport();
    return osObject;
}

summaryReport() ist eine void-Funktion, und es gibt mir eine Fehlermeldung:

kein operator "<<" entspricht diesen Operanden

aber der Fehler ist nicht da, wenn ich die summaryReport - Funktion zu einem int, aber ich habe das problem, das Sie haben, um einen Wert zurückzugeben, und es ist Druck auf dem Bildschirm.

void storageRentals::summaryReport() const
{
   for (int count = 0; count < 8; count++)
      cout << "Unit: " << count + 1 << "    " << stoUnits[count] << endl;
}

Gibt es eine Möglichkeit, um eine überlastung cout << mit einer void-Funktion?

InformationsquelleAutor Nick | 2012-04-24

Schreibe einen Kommentar