C++ - Why static member function can't be created with 'const' qualifier

前端 未结 5 850
没有蜡笔的小新
没有蜡笔的小新 2020-12-04 06:20

Today I got a problem. I am in the need of a static member function, const is not a must but a better. But, I didn\'t succeed in my efforts. Can an

5条回答
  •  情话喂你
    2020-12-04 06:26

    A 'const member function' is not allowed to modify the object it is called on, but static member functions are not called on any object. It is used directly by scope resolution operator. Thus having a const static member function makes no sense, hence it is illegal.

提交回复
热议问题