Reputation: 21
I am receiving this error when i compile "main.cpp: In constructor ‘TicTacToe::TicTacToe()’: main.cpp:38: error: array used as initializer " Any clues? thanks.
class chicken {
public:
chicken() : board("123456789") {};
private:
char board[10];
char player; // Switch after each move.
};
Upvotes: 0
Views: 186
Reputation: 34625
You cannot initialize the array like that. Instead use strcpy.
TicTacToe() {
strcpy(board,"123456789")
}
Or use std::string to make use of constructor initializer.
class TicTacToe {
public:
TicTacToe() : board("123456789") // Ok
{};
private:
std::string board ; // Changed to string type. There is no good reason to use
// character array when string type is available.
};
Upvotes: 3
Reputation: 3077
"123456789" has 10 characters because there is a NULL at the end.
Upvotes: 0