问题
I get compiler error by Clang 3.8 and GCC 5.3 if I want to declare my default
-ed default constructors as constexpr
. According to this stackoverflow question it just should work fine:
struct A
{
constexpr A() = default;
int x;
};
however:
Error: defaulted definition of default constructor is not constexpr
Have you got any clue what is actually going on?
回答1:
As it stands, x remains uninitialized, so the object can not be constructed at compile time.
You need to initialize x:
struct A
{
constexpr A() = default;
int x = 1;
};
来源:https://stackoverflow.com/questions/36392326/constexpr-defaulted-default-constructors