Static const declaration, constexpr definition of variable, valid c++?

后端 未结 2 1883
北恋
北恋 2020-12-18 23:09

Example: In header file:

class Foo
{
     static const int IntArray[];                         
};

In source file:

constexp         


        
2条回答
  •  甜味超标
    2020-12-18 23:55

    I doubt it's compliant. The declaration and definition are required to be identical AFAIK.

    It's certainly not portable. Although gcc, clang and microsoft cl 2017 accept it,

    ICC reports:

    (6): error: member "Foo::IntArray" (declared at line 3) was previously not declared constexpr
      constexpr int Foo::IntArray[] = { 1, 2, 3, 4 };
      ^
    compilation aborted for  (code 2)
    Compiler exited with result code 2
    

提交回复
热议问题