Which operator do I have to overload if I want to use sth like this?
MyClass C;
cout<< C;
The output of my class would be string.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
if you’ve to overload
operator<<as:If this function needs to access private members of
MyClass, then you’ve to make itfriendofMyClass, or alternatively, you can delegate the work to some public function of the class.For example, suppose you’ve a point class defined as:
Then you can overload
operator<<as:And you can use it as:
Output:
Online demo : http://ideone.com/zjcYd
Hope that helps.