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
Run Code Online (Sandbox Code Playgroud)
以上是我的Tic-Tac-Toe游戏头文件的一部分.我正在尝试测试win函数,并对如何从驱动程序文件测试它感到困惑:
#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
Run Code Online (Sandbox Code Playgroud)
我试图在main中创建一个Board :: Player类型,但仍然无法编译它.有什么建议?
小智 5
在C++中,你总是要考虑范围,所以:
cout << a.win(X) << endl;
Run Code Online (Sandbox Code Playgroud)
应该:
cout << a.win(Board::X) << endl;
Run Code Online (Sandbox Code Playgroud)