static const vs. const static

后端 未结 4 1007
一整个雨季
一整个雨季 2020-12-23 17:15

I do not understand the difference between these two statements in my C++ class:

class MyClass {
  public:
  private:
     static const int var = 0;                   


        
4条回答
  •  一向
    一向 (楼主)
    2020-12-23 17:47

    They mean exactly the same thing. You're free to choose whichever you think is easier to read.

    In C, you should place static at the start, but it's not yet required. I'm not sure if C++ followed C in this regard.

    6.11.5 Storage-class specifiers

    1 The placement of a storage-class specifier other than at the beginning of the declaration specifiers in a declaration is an obsolescent feature.

提交回复
热议问题