如何在头文件中使用外部枚举类型?
问题描述:
class Board
{
public:
enum Player {X = -1, O, E};
bool win(Player P); // A function that returns true if Player P has won the game, and
// false otherwise.
}; // end class board
以上是我的Tic-Tac-Toe游戏头文件的一部分。我想测试的胜利功能和困惑于如何从驱动程序文件进行测试:如何在头文件中使用外部枚举类型?
#include <iostream>
using namespace std;
#include "Board.h"
// function main begins program execution
int main()
{
Board a;
cout << a.win(X) << endl; // <------------------? ? ?
return 0; // indicate successful termination
} // end function main
我试图创建主一局::播放器类型,但仍无法得到它的编译。有什么建议么?
答
在C++中,你总是不得不考虑范围,所以:
cout << a.win(X) << endl;
应该是:
cout << a.win(Board::X) << endl;
太谢谢你了! – Brandon 2009-12-30 11:43:11