I agree with your question, but unfortunately C ++ is designed that way. For example:
class A { int i;
Today const considered in the context of this . In a way, it is narrowed. This can be made wider by applying this const pointer outside of this .
that is, the "suggested" const , which can also be applied to static functions, will limit the members of static from any modification.
In the code example, if foo() can be made const , then in this function A::s cannot be changed. I do not see any language side effects if this rule is added to the standard. On the contrary, itβs funny why such a rule does not exist!
iammilind Aug 12 2018-11-11T00: 00Z
source share