1
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?

1 Answer 1

5

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

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

should be:

cout << a.win(Board::X) << endl;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.