How do I intiailize the vector I have defined in my header file?

Posted by FrankTheTank on Stack Overflow See other posts from Stack Overflow or by FrankTheTank
Published on 2010-04-18T20:26:41Z Indexed on 2010/04/18 20:33 UTC
Read the original article Hit count: 418

Filed under:
|
|
|

I have the following in my Puzzle.h

class Puzzle
{
    private:
        vector<int> puzzle;
    public:
        Puzzle() : puzzle (16) {}
        bool isSolved();
        void shuffle(vector<int>& );
};

and then my Puzzle.cpp looks like:

Puzzle::Puzzle()
{
    // Initialize the puzzle (0,1,2,3,...,14,15)
    for(int i = 0; i <= puzzle.size(); i++)
    {
        puzzle[i] = i;
    }
}

// ... other methods

Am I using the initiailizer list wrong in my header file? I would like to define a vector of ints and initialize its size to that of 16. How should I do this?

G++ Output:

Puzzle.cpp:16: error: expected unqualified-id before ')' token
Puzzle.cpp: In constructor `Puzzle::Puzzle()':
Puzzle.cpp:16: error: expected `)' at end of input
Puzzle.cpp:16: error: expected `{' at end of input
Puzzle.cpp: At global scope:
Puzzle.cpp:24: error: redefinition of `Puzzle::Puzzle()'
Puzzle.cpp:16: error: `Puzzle::Puzzle()' previously defined here

© Stack Overflow or respective owner

Related posts about c++

Related posts about vector