Hey,
I have a class Foo, which has a member array of doubles, of length 5. This array is called x. I want x to be a constant array, such that the values in the array are never changed, and I know what I want them to be at the start of my program. However, I don't seem to be able to do this in a concise manner. Here is what I tried :
This does not work. Nor does:Code:class Foo { const double x[5] = {1, 2, 3, 4, 5}; }
The only way that works is:Code:class Foo { const double x[5]; public Foo() { x = {1, 2, 3, 4, 5,}; }
But this obviously becomes a very long-winded approach when using larger arrays.Code:class Foo { const double x[5]; public Foo() { x[0] = 1; x[1] = 2; x[2] = 3; x[3] = 4; x[4] = 5; } }
Please could somebody explain what is going on here?
Thanks![]()



LinkBack URL
About LinkBacks



