Visual c++ 如何使用头文件中的外部枚举类型?
以上是我的Tic Tac Toe游戏头文件的一部分。我正在尝试测试win功能,但对如何从驱动程序文件测试它感到困惑:Visual c++ 如何使用头文件中的外部枚举类型?,visual-c++,enums,Visual C++,Enums,以上是我的Tic Tac Toe游戏头文件的一部分。我正在尝试测试win功能,但对如何从驱动程序文件测试它感到困惑: 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.
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
我试图在main中创建Board::Player类型,但仍然无法编译它。有什么建议吗? < p>在C++中,你总是要考虑范围,所以:
#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
应该是:
cout << a.win(X) << endl;
在C++中,你总是要考虑范围,所以:
#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
应该是:
cout << a.win(X) << endl;