• Advertisement
Sign in to follow this  

Passing a 2d vector array as a pointer

This topic is 2266 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!!!

Share this post


Link to post
Share on other sites
Advertisement
You could try pass by reference (& instead of *) since that seems to be how you're trying to use it.

Share this post


Link to post
Share on other sites
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
}
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement