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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include<iostream>
#include<limits>
usingnamespace std;
class TicTacToe {
public:
void displayBoard();
void getMove();
void playGame();
private:
char board[9];
char player; // Switch after each move.
};
public:
TicTacToe() : board() {}; // Zero initialize
TicTacToe() : board("12345678") {}; // This works but you need to leave room for an implicit null character
VS 2010 here, I tried the 2nd initialization on a whim, and to my surprise it worked. I suspect when raw literals are introduced this might be a more viable initialization.. though by then we would hopefully have support for initializer lists. (GCC already does I think?)