const int* const Method3(const int* const&) const;
Can someone explain the usage of each of the const?
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.
Read this: https://isocpp.org/wiki/faq/const-correctness
The final
constmeans that the functionMethod3does not modify the non mutable members of its class.const int* constmeans a constant pointer to a constant int: i.e. a pointer that cannot be changed, to an int that cannot be changed: the only difference between this andconst int&is that it can benullconst int* const&means a reference to a constant pointer to a constant int. Usually pointers are not passed by reference;const int* &makes more sense because it would mean that the pointer could be changed during the method call, which would be the only reason I can see to pass a pointer by reference,const int* const&is to all intents and purposes the same asconst int* constexcept that it is probably less efficient as pointers are plain old data (POD) types and these should, in general be passed by value.