CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2007
    Posts
    13

    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.

  2. #2
    Join Date
    Aug 2005
    Location
    LI, NY
    Posts
    576

    Re: Syntax for initializing Arrays within Class Constructors Initialization List

    Quote Originally Posted by RobotJones
    it can't be done.
    Unfortunately.
    - Alon

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured