g++ 4.7 supports array member initialization 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;
The error message with gcc 4.8 (prerelease) is:
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 a way to make this code work? I can't easily change the contructors,destructor of A. I seem to need a move-constructor or copy-constructor to initialize the array, but this seems counter-intuitive, since all I really want is in-place construction.
It works if I split a[2] in 2 members a0 and a1, and construct them separately. This looks fishy however.