Problem with enums.

I'm writing a quick tic tac toe game but my plan is to pass the enum PLAYERS, to the function "firstGuess()", when trying to pass the enum, it tells me "type name is not allowed?". Any help would be awesome. Thanks.

Oops accidentally deleted the other. :(

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Tic Tac Toe

#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>

using namespace std;

void displayInstructions();
void displayBoard(int number, const vector<int>& board, vector<int>::iterator& boardIter);
int computerGuess();
int firstPlayer(enum PLAYERS);

int main() {

	vector<int> board;
	vector<int>::iterator boardIter;
	enum PLAYERS { HUMAN, COMPUTER };

	displayInstructions();
	firstPlayer(PLAYERS);

	if (firstPlayer(PLAYERS) == 0) {
		//get humans move
	}
	else {
		//calculate computers move
	}

	return 0;
}

void displayInstructions() {
	cout << "Welcome to Tic-Tac-Toe!\n\n";
	cout << "To make a move, please type a number that corresponds with a place on the board.";
	cout << "Good luck!\n" << endl;
}

void displayBoard(int number, const vector<int>& board, vector<int>::iterator& boardIter) {


}

int computerGuess() {


}

int firstPlayer(PLAYERS player) {
	
}
Last edited on
The enum must be known before you can use it.

I.e. move line 21 (which is local to main) before line 15 (remove the enum keyword there)

[EDIT]
On line 21 you certainly mean something like that:

PLAYERS player = HUMAN; // define a variable of the type PLAYERS with the initial value HUMAN
Last edited on
 
enum PLAYERS { HUMAN, COMPUTER };
This defines an enumeration named PLAYERS. Note that PLAYERS is a type and not an object.

 
PLAYERS player = HUMAN;
This creates a PLAYERS variable named player with the value HUMAN.

 
firstPlayer(player);
This is how you can pass the variable to the function.
Oh right that makes much more sense to me.

I didn't realise that I defined a type, not an object. So essentially on the code PLAYERS player = HUMAN;, "player" is a reference to the HUMAN that is of type enum?

I know it's not a "reference" , I'm just using that word as an analogy.
Topic archived. No new replies allowed.