If you want to be able to do std::cout << AutoData();
, you need to overload the output stream operator operator<<
:
std::ostream& operator<< (std::ostream &out, AutoData const& data) {
out << data.getmpg() << ':';
out << data.getcylinders() << ':';
// and so on...
return out;
}
This function is not a member function, and since you have getters for each attribute, you do not have to declare this function as friend
of your class.
Then you can do:
AutoData myAuto;
std::cout << myAuto << '\n';