Meaning of 'const' last in a function declaration of a class?

后端 未结 10 2116
无人共我
无人共我 2020-11-21 06:37

What is the meaning of const in declarations like these? The const confuses me.

class foobar
{
  public:
     operator int () const         


        
10条回答
  •  闹比i
    闹比i (楼主)
    2020-11-21 07:19

    Blair's answer is on the mark.

    However note that there is a mutable qualifier which may be added to a class's data members. Any member so marked can be modified in a const method without violating the const contract.

    You might want to use this (for example) if you want an object to remember how many times a particular method is called, whilst not affecting the "logical" constness of that method.

提交回复
热议问题