I'm having a hard time with "enum class". I understand it is a C++11 feature and also I've read about the differences between enum class and plain enums.
I have declared a "Token" enum class:
Token.h
enum class Token
{
EMPTY,
BLACK,
WHITE
};
and a "Game" class, that uses the Token class:
Game.h
#include <Board.h>
#include <Token.h>
class Game
{
public:
Game();
~Game();
...
private:
Board board;
Token turn;
bool endGame;
Token winner;
};
Game.cpp
Game::Game()
{
Board board(6,7); //Create board with 6*7 size
board.reset(); //Reset the board
turn=Token::WHITE; //First turn for WHITE player
endGame=false;
winner=Token::EMPTY;
}
...
The compiler gives me the following error for the constructor for Game:
In constructor Game::Game() error: 'Token' is not a class or namespace
The same error happens for any use of a Token class variable inside the Game class.
If I transform the enum class in just an enum and remove the "Token::" references before the use of the enum values, it works perfectly. What is happening?
P.D.- FYI, I'm new in C++ programming, but I have experience with PASCAL, C and in OOP with Java.
Aucun commentaire:
Enregistrer un commentaire