g ++ 4.7 supports the initialization of an array member, and I started playing with it.
The code below does not compile.
struct A { A(int){}; A(const A&) = delete; A& operator=(const A&) = delete; ~A(){}; }; struct B { B(): a{{0},{1}} {}; A a[2]; }; B b;
Error message with gcc 4.8 (preerelease):
n.cc: In constructor 'B::B()': n.cc:12:20: error: use of deleted function 'A::A(const A&)' a{{0},{1}} ^ n.cc:4:8: error: declared here A(const A&) = delete; ^
Is there any way to make this code work? I can't easily change the constructors, destructor A. It seems I need a move constructor or a copy constructor to initialize the array, but this seems to contradict intuition, since all I really need is to build in place.
It works if I split [2] into 2 members a0 and a1 and create them separately. However, this looks suspicious.
source share