Brandon Tiqui
Brandon Tiqui

Reputation: 1439

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?

Upvotes: 1

Views: 483

Answers (1)

anon
anon

Reputation:

In C++, you always have to think about scope, so:

cout << a.win(X) << endl;

should be:

cout << a.win(Board::X) << endl;

Upvotes: 5

Related Questions