Here’s the code that I have a problem with:
class Foo {
public:
Foo() :
memberArray{Bar(1), Bar(3), Bar(2)}
{}
struct Bar {
Bar(int param1) { }
};
private:
std::array<Bar,3> memberArray;
// Bar memberArray[3]; // Using a raw array like this instead compiles fine..
};
I’m using GCC 4.6.1, and compiling for c++11. How should I initialise my std::array?
Since
array<T, N>is actually a struct, the fully braced version needs{{ .. }}(the inner ones are for the array member of thearray<T, N>object). The spec does not allow brace elision here. It only allows it in a declaration of the formSo you have to use fully braced syntax
This is not a GCC bug, but required by the spec.