What's the use of const here

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

    When the function is marked const it can be called on a const pointer/reference of that class. In effect it says This function does not modify the state of the class.

提交回复
热议问题