In order to use cout as such : std::cout << myObject, why do I have to pass an ostream object? I thought that was an implicit parameter.
ostream &operator<<(ostream &out, const myClass &o) {
out << o.fname << " " << o.lname;
return out;
}
Thanks
You aren’t adding another member function to
ostream, since that would require redefining the class. You can’t add it tomyClass, since theostreamgoes first. The only thing you can do is add an overload to an independent function, which is what you’re doing in the example.