I have a template base class, whereby subclasses are expected to pass themselves as the template parameter.
It looks a little like this:
template<
I think you shall use lazy initialization. Actually Derived
is still incomplete type; because the compiler don't know its size yet.
So the code shall be:
struct Derived : public Base<Derived>
{
constexpr Derived(int x) : Base(x) {}
static constexpr Derived getLIFE()
{
return Derived(34);
}
};
EDIT:
Same incomplete type
behavior can be reproduced using this snippet:
struct MyStruct
{
static constexpr int x = sizeof(MyStruct);
};
You can simply add constexpr
to the definition of LIFE
:
constexpr Derived Derived::LIFE = Derived(42);
Until recently GCC had a bug where it rejected this; you'll need to use either Clang or GCC 4.9.