I want to overload the “receiver” operator so I can do this: someClass >> myClass.
…where myClass is the class which I need to overload the operator for.
Hope that makes sense.
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.
As @Mysticial pointed out, you need to overload
operator>>to do this.That overload can not be a member of
myClassthough. It must be either a member ofsomeClass, or else a global overload.or:
If the operator doesn’t/can’t change the state of the
someClassobject, you might want to pass the first parameter by const reference (in which case you’d also return a const reference).Of course, returning a
someClassisn’t really required, but it’s the normally accepted practice for this kind of operator (it allows chaining the operators for something likea >> b >> c;)