Too much C# and too little C++ makes my mind dizzy… Could anyone remind me what this c++ declaration means? Specifically, the ending “const”. Many thanks.
protected:
virtual ostream & print(ostream & os) 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.
A
constmethod will simply receive aconstthispointer.In this case the
thispointer will be of theconst ThisClass* consttype instead of the usualThisClass* consttype.This means that member variables cannot be modified from inside a
constmethod. Not even non-constmethods can be called from such a method. However a member variable may be declared asmutable, in which case this restriction will not apply to it.Therefore when you have a
constobject, the only methods that the compiler will let you call are those marked safe by theconstkeyword.