0
How to overload << operator?
I need overload << operator. For example: class myClass{...}; myClass a; cout<<a; //this must write in console all elements of char array (arr) from object a of myClass.
1 Odpowiedź
+ 6
The basic signature is
std::ostream& operator << ( std::ostream&, const MyClass& );
Usually, you declare this as a friend function to your class, so that it has access to the private properties of the class, although this really depends on what you want to write into the output stream.
Inside the definition, you can then use the std::ostream instance the same way you use std::cout. Don't forget to return that instance at the end.