class C
{
public:
C() : arr({1,2,3}) //doesn't compile
{}
/*
C() : arr{1,2,3} //doesn't compile either
{}
*/
private:
int arr[3];
};
I believe the reason is that arrays can be initialized only with =
syntax, that is:
int arr[3] = {1,3,4};
Questions
- How can I do what I want to do (that is, initialize an array in a constructor (not assigning elements in the body)). Is it even possible?
- Does the C++03 standard say anything special about initializing aggregates (including arrays) in ctor initializers? Or the invalidness of the above code is a corollary of some other rules?
- Do C++0x initializer lists solve the problem?
P.S. Please do not mention vectors, boost::arrays, and their superiority to arrays, which I am well aware of.