trouble with pointers

Apr 2, 2012 at 4:54am
I am trying to use certain variables accross multiple functions so I have used pointers and it works accross the majority of my code but when I get to the function that calls all the other functions and acctually runs the program it tells me that the identifyers are undefined
Apr 2, 2012 at 5:12am
maybe if you could elaborate or post some code, it will be easier for people to help
Apr 2, 2012 at 5:16am
this is where the problems are arising
1
2
3
4
5
6
7
8
9
10
11
12
13
while (checkEndGame == 0 && numTurn < 9)
	{
		askMove(*mref);
		verifyMakeMove(gameBoard,BOARD_SIZE, *pref, *mref);
		printBoard(gameBoard,BOARD_SIZE);
		if (*pref = 1)
		{
			*pref ++;
		}
		else
		{
			*pref --;
		}

this is the declaration of the pointer
1
2
int player = 1;
int* pref = &player;
Apr 2, 2012 at 5:24am
how are your function declarations set up?
Apr 2, 2012 at 5:26am
like this
bool verifyMakeMove(char gameBoard[],int BOARD_SIZE, int& mref, int& pref);
Apr 2, 2012 at 5:29am
is that the function code for the code above?
Apr 2, 2012 at 5:34am
no the above code is part of
int playGame();
but playGame's main purpose is simply calling the other functions in a specific order
Apr 2, 2012 at 5:41am
since arrays are pointers, you could simply pass gameBoard as a pointer and take the address of that..? i dunno it looks fine to me
Apr 2, 2012 at 5:49am
there are no problems with gameBoard its mref and pref they give me this error message
Error	5	error C2065: 'pref' : undeclared identifier

and seven others the same one for each time they're mentioned in that loop and I dont see why considering they work throughout the rest of the program
Apr 2, 2012 at 8:00am
could it be something to do with the order in which the functions are called and when the pointers are declared
Apr 2, 2012 at 10:24am
I am really hoping that its a simple mistake causeing this something that dosent require me to go back and completely re-code the program
Apr 2, 2012 at 10:46am
closed account (1vRz3TCk)
jax666999 wrote:
error C2065: 'pref' : undeclared identifier
Does the error message not tell you enough? There is no identifier in scope that is called pref.

Also:
your function declarations is using references not pointers;

the order that you are calling the parameters look different to the order they are declared;

and you may want to look at if (*pref = 1), I don't think that that is what you want to be doing.
Topic archived. No new replies allowed.