I have a bootstrap problem with a constexpr static member of a class Bar
which is an array of Bar
itself. Consider the following perfectly correct code:
struct Foo {
int i;
static const std::array<Foo, 2> A;
};
const std::array<Foo, 2> Foo::A {{{1},{2}}};
Now I'd like to have Foo::A
not only const but also constexpr
. I'm faced
with the problem that static constexpr member initialization must be done
inside the class declaration. However, since the declaration is not yet finished,
the compiler doesn't yet know the size of an instance and therefore refuse to
make the array. For example
struct Bar {
int i;
constexpr static const std::array<Bar, 2> A{{{1},{2}}};
};
is refused with
/usr/include/c++/4.8/array: In instantiation of ‘struct std::array<Bar, 2ul>’:
ess.cpp:14:56: required from here
/usr/include/c++/4.8/array:97:56: error: ‘std::array<_Tp, _Nm>::_M_elems’ has incomplete type
typename _AT_Type::_Type _M_elems;
Is there a way to solve that ? Or a workaround ?