随笔-64  评论-13  文章-2  trackbacks-0


The parameter right was declared const. That means the object is const inside the operator function. But, const objects can only call const member functions because const objects must have a guarantee that they won't be changed. Since the operator<() function wasn't defined as const.

a const object can't call the function. The reason is that every class method has an invisible parameter: the this pointer. The this pointer can implicity or explicity be used inside the function to change the object, e.g.:

setPrivateVar(10);

or

this->setPrivateVar(10);

When you declare a member function const, the compiler will ensure that no changes can be made to the calling object.
posted on 2010-05-22 13:53 桂湖山 阅读(409) 评论(0)  编辑 收藏 引用
只有注册用户登录后才能发表评论。