Why there is no concept of “const-correctness” for class's static member functions?

后端 未结 6 754
别那么骄傲
别那么骄傲 2020-12-19 01:13

Use case:

class A {
  static int s_common;
public:
  static int getCommon () const { s_common; };
};

Typically this results in an error as:

6条回答
  •  梦毁少年i
    2020-12-19 01:54

    My guess is that using static and const on a member function to refer to constness of static member variables was simply never considered as an option. IMO your suggestion is kind of a strange (but maybe sensible) way of mixing those two keywords.

提交回复
热议问题