0

Possible Duplicate:
How can i use member initialization list to initialize it?

I am trying to initialize an array in my constructor and storing it in my char board[]. I am not sure how I can do this. I just want to initialize the value for board so i can replace it later.

Community
  • 1
  • 1
user868756
  • 21
  • 5

3 Answers3

3
  TicTacToe::TicTacToe() : board() { }

You should read up on a little more C++ and a good place would be the article linked in the comment on your question.

squinlan
  • 1,795
  • 15
  • 19
0

I had heard that C++ did not support colon-init lists for arrays until just recently, I think.

TicTacToe() : board()
{ }

This should work, like squinlan said. If not, you can always just assign whatever values you are trying to initialize the board to within the constructor.

0

If you want to stick with array of char you could add the constructor:

    void TicTacToe() {memset (board, 0, 9);}//this is new

to your class definition

class TicTacToe {
public:
    void displayBoard();
    void getMove();
    void playGame();

    TicTacToe() {memset (board, 0, 9);}//this is new

private:
    char board[9];
    char player; // Switch after each move.
};
Ioan Paul Pirau
  • 2,733
  • 2
  • 23
  • 26