How can I initialize an array of type int inside a class constructor's initialization list?
My guess is that I'd either do it similarly to when I initialize an array normally, but with parenthesis rather than curly braces:Code:class myClass { public: myClass(void); private: int myArray[4]; };
OR, maybe I'll have to initialize each element separately, like:Code:myClass::myClass(void) : myArray(1, 2, 3, 4) { }
OR, maybe it can't be done. I'm not sure what syntax, if any, is correct. Can anyone help me out? Thanks.Code:myClass::myClass(void) : myArray[0](1), myArray[1](2), myArray[2](3), myArray[3](4) { }




Reply With Quote