I would like a class C to have a static constexpr member of type C. Is this possible in C++11?
Attempt 1:
struct Foo {
constexpr Foo() {}
static constexpr Foo f = Foo();
};
constexpr Foo Foo::f;
g++ 4.7.0 says: 'invalid use of incomplete type' referring to the Foo() call.
Attempt 2:
struct Foo {
constexpr Foo() {}
static constexpr Foo f;
};
constexpr Foo Foo::f = Foo();
Now the problem is the lack of an initializer for the constexpr member f inside the class definition.
Attempt 3:
struct Foo {
constexpr Foo() {}
static const Foo f;
};
constexpr Foo Foo::f = Foo();
Now g++ complains about a redeclaration of Foo::f differing in constexpr.