For a school assignment we were instructed to make a TicTacToe Board. My program currently works, but here are some issues I encountered, and I'm not too sure why they are incorrect:
class TicTacToe{
private:
char user_Turn[] = {'x','o'}; //Array to keep track of turn
When I try and compile with that I get an error and warning. The warning is "in-class initialization of non-static data member is a C++11 extension". Is it bad practice to initialize non-static data members in-class? Why?
The error is "array bound cannot be deduced from an in-class initializer". When I put a '2' in the array this goes away. So arrays in classes need to be bound? Why is that? And why can't the bounds be deduced by initializer?
My second question is that the same project required us to use an enumerated object to declare a winner/loser/draw in a separate class called Board. The enum is publically declared:
public:
enum Game {X_WON, O_WON, DRAW, UNFINISHED}; //enum declaration
and my TicTacToe class has a Board object as a data member called board1. How come to use the enum I need to do:
Board::UNFINISHED
and not
Board.UNFINISHED
Additionally, even in my Board implementation file, I need to do this to a function that returns an enumerated variable:
Board::Game Board::gameState()
It's in the same class so why does Game need to be proceeded by 'Board::'. I suppose I have little understanding enums works with classes.
Thank you! Much appreciated to whoever answers.
Aucun commentaire:
Enregistrer un commentaire