What's the use of const here

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

    It's a const method. It means that it won't modify the member variables of the class nor will it call non-const methods. Thus:

    const foo bar;
    bar.m();
    

    is legal if m is a const method but otherwise wouldn't be.

    0 讨论(0)
提交回复
热议问题