sizeof in static const member initialization

前端 未结 4 1181
攒了一身酷
攒了一身酷 2021-01-23 14:00

I have such code:

class A
{
public:

    unsigned long a;
    static const unsigned long b = sizeof(a); // \"error C2327: \'A::a\' : is not a type name, static,          


        
4条回答
  •  太阳男子
    2021-01-23 14:36

    static const-qualified member in-class initialisers using non-static members were not part of the C++ standard until C++11.

    The earliest MSVC compiler that fully supports C++11 is MSVC2017.

    That compiler will compile your code correctly.

提交回复
热议问题