我正在处理一个代码块,并且在TTTEnum.h文件中有一个枚举声明:
#ifndef TTTEnum
#define TTTEnum
enum class Winner
{
Empty,
Computer,
Player
};
#endif
我有另一个头文件,即TTT.h,我尝试将我的函数的所有原型放在这里,看起来如下:
#ifndef TTT_H_INCLUDED
#define TTT_H_INCLUDED
#include "TTTEnum.h"
#include <iostream>
#include <cmath>
using namespace std;
TTTEnum::Winner gameSquares[] = { Empty, Empty, Empty, Empty,
Empty, Empty, Empty,Empty, Empty };
class TTT
{
public:
int movesMade = 0;
void HowTo();
void PlayerTurn();
bool FirstGo();
int GetPossibleMoves(int possible_index[9], Winner who, const Winner *const board = gameSquares);
int GetWinIndex(const Winner who);
void ComputerTurn();
void PrintBoard();
};
#endif
当我编译这些代码时,我会得到8-9行错误,这些错误都是“空”在这个范围内没有声明的。我一直在检查其他枚举问题,当您试图将枚举调用到其他文件时,我发现枚举非常棘手。有什么解决办法能帮我吗?
发布于 2014-05-21 06:12:44
如果您使用的是Empty
(按Winner
),则需要使用enum class
来限定名称enum class
的范围。
也就是说,Winner::Empty
而不仅仅是Empty
应该能工作。
https://stackoverflow.com/questions/23775227
复制相似问题