I know it's recommended that class declarations should be in the header file and class member initialization should be in the source file. However, since my struct object (compound
) is declared as static constexpr
, I believe I can define it within the header file (shown below).
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;
}
}
However, this gives me a level 4 compiler (MSVS 2015) warning (C4268 - shown above in test.h) stating:
'private: static common::abc compound common::def::xyz::foo':'const'
static/global data initialized with compiler generated constructor fills the
object with zeros
What does this warning mean? Is there a better way of initializing this struct?