Possible Duplicate:
Intitialzing an array in a C++ class and modifiable lvalue problem
As seen in this question, it’s possible to give a ctor to a struct to make it members get default values. How would you proceed to give a default value to every element of an array inside a struct.
struct foo
{
int array[ 10 ];
int simpleInt;
foo() : simpleInt(0) {}; // only initialize the int...
}
Is there some way to make this in one line similar to how you would do to initialize an int?
Thew new C++ standard has a way to do this:
test: https://ideone.com/enBUu
If your compiler does not support this syntax yet, you can always assign to each element of the array:
EDIT: one-liner solutions in pre-2011 C++ require different container types, such as C++ vector (which is preferred anyway) or boost array, which can be boost.assign‘ed