I try to overload operator<< for my class so that it print member when I do std::cout << obj;
I see that the way to do this is
std::ostream& operator<<(std::ostream& os, const T& obj)
{
// write obj to stream
return os;
}
What are the basic rules and idioms for operator overloading?
However, I try to make my code conforms to Google C++ style guide https://google.github.io/styleguide/cppguide.html#Reference_Arguments
It says that passing the reference without const is not allowed except for the case that it is needed by convention such as swap(). Is this overloading operator<< in the same category as swap()? or there is a way to do something like
std::ostream& operator<<(std::ostream* os, const T& obj)
^
? or something that does not take non-const reference as the input.
If so, please teach me how to do that. Thank you.