Possible Duplicates:
c++ const use in class methods
Meaning of “const” last in a C++ method declaration?
int operator==(const AAA &rhs) const;
This is a operator overloading declaration. Why put const at the end? Thanks
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.
The
constkeyword signifies that the method isn’t going to change the object. Sinceoperator==is for comparison, nothing needs to be changed. Therefore, it isconst. It has to be omitted for methods likeoperator=that DO modify the object.It lets the compiler double-check your work to make sure you’re not doing anything you’re not supposed to be doing. For more information check out http://www.parashift.com/c++-faq-lite/const-correctness.html.