Proper initialization of static constexpr array in class template?

前端 未结 2 1186
无人共我
无人共我 2021-01-07 20:12

Static class members in C++ have caused a little confusion for me due to the standard\'s verbiage:

9.4.2 Static data members [class.sta

2条回答
  •  天命终不由人
    2021-01-07 20:46

    In case it helps anyone out, the following worked for me with GCC 4.7 using constexpr:

    template class X {
      constexpr static int s = 0;
    };
    template constexpr int X::s; // link error if this line is omitted
    

    I'm not making any claims of whether this is "proper". I'll leave that to those more qualified.

提交回复
热议问题