Skip to main content
GameDev.net gamedev.net
🔒 Locked

Passing a 2d vector array as a pointer

Started by lehthanis Dec 13, 2011 at 3:29 PM 1 replies 1.2k views
Original Post
lehthanis
lehthanis
I've got a maze generator program I've been working on as a learning tool. I wanted to create a scoring mechanism for user solving, and to do that I need to know in advance what the solution is. I have code that automatically solves the maze. And I am using bitwise logic to store the state of each maze cell in my vector array.

As the user solves the maze, they are storing in the primary array their progress. I wanted to keep that, but make a duplicate vector array that has the computer's solve path's stored in it. So I figured I could pass to the function that solves the maze (and handles pathing) which array to work on via pointer. like this:


// This is the call for the users pathing in the maze
solveMaze(&glMaze)
// This is the call for the computers pathing in the maze
solveMaze(&glMazeSolution)

// ...

// Here's the function and just the line that I'm getting the error
bool solveMaze(vector<vector<int> > * maze)
{
if (((maze[CurrRow -1][CurrCol] & ALL_PATHS) == 0) && ((maze[CurrRow -1][CurrCol] & ALL_BACKS) == 0)) {
// Do Stuff
}
}


The error I'm getting is: binary '&' : 'std::vector<_Ty>' does not define this operator or a conversion to a type acceptable to the predefined operator

So is there a different/better/correct way to pass a multidimensional vector to a function as a pointer that won't cause this problem?

Thanks!!!
I work with X-Plane
SiCrane
SiCrane
You could try pass by reference (& instead of *) since that seems to be how you're trying to use it.
lehthanis
lehthanis
That seemed to work. Is this what you meant:


// This is the call for the users pathing in the maze
solveMaze(glMaze)
// This is the call for the computers pathing in the maze
solveMaze(glMazeSolution)

// ...

// Here's the function and just the line that I'm getting the error
bool solveMaze(vector<vector<int> > & maze)
{
if (((maze[CurrRow -1][CurrCol] & ALL_PATHS) == 0) && ((maze[CurrRow -1][CurrCol] & ALL_BACKS) == 0)) {
// Do Stuff
}
}
I work with X-Plane

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.