Syntax for initializing Arrays within Class Constructors Initialization List
How can I initialize an array of type int inside a class constructor's initialization list?
Code:
class myClass
{
public:
myClass(void);
private:
int myArray[4];
};
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:
myClass::myClass(void)
: myArray(1, 2, 3, 4)
{
}
OR, maybe I'll have to initialize each element separately, like:
Code:
myClass::myClass(void)
: myArray[0](1), myArray[1](2), myArray[2](3), myArray[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.
Re: Syntax for initializing Arrays within Class Constructors Initialization List
Quote:
Originally Posted by RobotJones
it can't be done.
Unfortunately.