[C++] Constant Member Functions

Declaring a member function with the const keyword specifies that the functi
on is a “read-only” function that does not modify the object for which it is
called.To declare a constant member function, place the const keyword after the clo
sing parenthesis of the argument list. The const keyword is required in both
the declaration and the definition. A constant member function cannot modif
y any data members or call any member functions that aren’t constant.
就是类的成员函数如果声明const在最后则表示该函数不会修改该类的任何成员变量
Const的使用可以参见NewSmth的Cplusplus版精华区voidluner的[FAQ]const使用详解

Leave a Reply