How to declare constexpr extern?

前端 未结 6 931
耶瑟儿~
耶瑟儿~ 2020-11-29 07:43

Is it possible to declare a variable extern constexpr and define it in another file?

I tried it but the compiler gives error:

De

6条回答
  •  伪装坚强ぢ
    2020-11-29 08:20

    What you probably want is extern and constexpr initialization, e.g.:

    // in header
    extern const int g_n;
    
    // in cpp
    constexpr int g_n = 2;
    

    This is support though in Visual Studio 2017 only through conformance mode:

    • /Zc:externConstexpr (Enable extern constexpr variables)
    • constexpr definition of extern const variable

提交回复
热议问题