初始化私有静态复合constexpr值

时间:2018-10-09 12:24:40

标签: c++ c++11 initialization compiler-warnings

我知道recommended的类声明应该在头文件中,而类成员的初始化应该在源文件中。但是,由于我的结构对象(compound)被声明为static constexpr,所以我相信我可以在头文件中定义它(如下所示)。

header1.h:

namespace common
{
   namespace abc
   {
      struct compound
      {
         unsigned int intgr1;
         unsigned int intgr2;
         unsigned int intgr3;
      };
   }
}

test.h:

#include "header1.h"

namespace common
{
   namespace def
   {
      class xyz
      {
         // public: ...

         private:
            static constexpr abc::compound foo = 
               {0, 1, 2}; // <--- C4268 warning here
      };
   }
}

test.cpp:

#include "test.h"

namespace common
{
   namespace def
   {
      constexpr abc::compound xyz::foo;
   }
}

但是,这给了我4级编译器(MSVS 2015)警告(C4268-上面在test.h中显示),说明:

'private: static common::abc compound common::def::xyz::foo':'const' 
static/global data initialized with compiler generated constructor fills the   
object with zeros

此警告是什么意思?有没有更好的方法初始化该结构?

0 个答案:

没有答案
相关问题