How does const after a function optimize the program?

前端 未结 6 2009
星月不相逢
星月不相逢 2021-01-31 05:29

I\'ve seen some methods like this:

void SomeClass::someMethod() const;

What does this const declaration do, and how can it help optimize a prog

6条回答
  •  野性不改
    2021-01-31 06:04

    My first thought regarding optimization is that since the 'const' indicates that the instance's state hasn't changed, the compiler possibly has more freedom with respect to reordering nearby calls to methods on that instance.

提交回复
热议问题