Why I can’t create or overload operator := in my class in C++?
Is there are some list operators that I can overload?
I can only overload, or also create some new custom operators?
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.
Because no such operator exists in C++. You cannot roll your own operators because you would need to modify the grammar of the language for the parser to recognize them.
You can find a list of the available operators here or here (or better yet by reading the standard if you can get a copy).
Finally, be advised that overloading operators like there is no tomorrow is a mistake that pretty much every C++ beginner makes; operators are really nothing more than functions, and unless there is a very good case to be made for overloading an operator most of the time it’s a better idea to just write a plain function for your class instead. For example,
std::stringdoes not have anoperator*even though it could be argued that it’s convenient to write