How do I use an enum type external from a header file?
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
The above is part of my header file for a Tic-Tac-Toe game. I am trying test the win function and confused on how to test it from 开发者_运维知识库a driver file:
#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
I have tried to create a Board::Player type in main but still cannot get it to compile. Any suggestions?
In C++, you always have to think about scope, so:
cout << a.win(X) << endl;
should be:
cout << a.win(Board::X) << endl;
精彩评论