What's the use of const here

前端 未结 7 1838
借酒劲吻你
借酒劲吻你 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:22

    It's a const member function. It's a contract that the function does not change the state of the instance.

    more here: http://www.fredosaurus.com/notes-cpp/oop-memberfuncs/constmemberfuncs.html

提交回复
热议问题