What's the use of const here

前端 未结 7 1837
借酒劲吻你
借酒劲吻你 2021-01-21 13:09

in

int salary() const { return mySalary; }

as far as I understand const is for this pointer, but I\'m not sure. Can any one tell me what is the us

7条回答
  •  情歌与酒
    2021-01-21 13:16

    It just guarantees that calling salary() doesn't change the object state. IE, it can be called with a const pointer or reference.

提交回复
热议问题