Operator= in C++ inside a class is being declared like this:
MyType & operator=(const MyType & rhs);
It is reasoned like it is necessary for chaining. But, as operator= has right precedence, then returning the value should be enough.
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.
You certainly can declare
operator =with a non-reference return type. In fact, on the very rare occasions I implement it, I normally make it returnvoidas I don’t think that multiple assignments, or testing the result of assignment, are one of C++’s greatest features.