Im trying something like this (which doesnt compile):
struct mystruct {
somestruct arr[4];
mystruct(somestruct val) : arr[0](val), arr[1](val), arr[2](val), arr[3](val) {}
};
How is this best done in c++ ?
Note: i might want to set only some of the array elements with this method.
In C++11, if you want to set all the elements:
mystruct(somestruct val) : arr{val,val,val,val} {}
In C++03, or C++11 if you only want to set some elements:
mystruct(somestruct val) {
arr[0] = val;
arr[1] = val;
arr[2] = val;
arr[3] = val;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With