In C++98 you can't. But if you dig into the murky past of C++ and it's C heritage then you can. The thing that gets around this is the fact that if an array is part of another structure or class it gets
copied along with everything else when the structure is copied. So if anyone tells you that you can't return an array by value, tell them of course you can:
struct B
{
int data[15];
};
B grab_a_B()
{
B b;
b.data[0] = 125;
return b;
};
So how does this help you? Well instead of using a const array in your class, use a const instance of a structure instead:
class A
{
public:
A( const B &b ) : b_( b ) {}
private:
const B b_;
};
Initialise a B, feed it to an A and snip, snip, Bob's yer aunty.
In C++11 there is a feature (uniform initialisation) that you can use to do the same thing. So you can do something like:
class A
{
public:
A(): arr( {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15} ) {}
private:
const int arr[ 15 ];
};
although the syntax is from memory. Visual Studio up 'til 2010 doesn't support this, I'm not sure about gcc whether gcc does either.