<<
OperatorTo redefine the <<
operator so that you use it with cout
to display an object’s contents, you define a friend operator function that has the following form:
ostream & operator<<(ostream & os, const c_name & obj)
{
os << ... ; // display object contents
return os;
}
Here c_name
represents the name of the class. If the class provides public methods that return the required contents, you can use those methods in the operator function and dispense with the friend status.
3.15.168.214