When should a member function have a const qualifier and when shouldn't it?

后端 未结 6 1306
轻奢々
轻奢々 2021-02-06 09:04

About six years ago, a software engineer named Harri Porten wrote this article, asking the question, \"When should a member function have a const qualifier and when shouldn\'t i

6条回答
  •  无人共我
    2021-02-06 09:16

    when it doesn't modify the object.

    It simply makes this to have type const myclass*. This guarantees a calling function that the object won't change. Allowing some optimizations to the compiler, and easier for the programmer to know if he can call it without side effects (at least effects to the object).

提交回复
热议问题