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

前端 未结 5 853
没有蜡笔的小新
没有蜡笔的小新 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:48

    Without getting into the details, it's because there may or may not be an object modified by the function, so const is ambiguous to the compiler.

    Recall that const keeps objects constant, but there may or may not be an object here to keep constant.

提交回复
热议问题