Since, you didn't posted the code of how you are obtaining the values, compare to this, and try to find your problem...
std::vector<std::vector<Field*> > maze; // Ini for(int i = 0; i < MAZE_WIDTH; i++) { maze.push_back(std::vector<Field*>()); for(int j = 0; j < MAZE_HEIGHT; j++) { maze[i].push_back(new Field()); maze[i][j]->x = i; maze[i][j]->y = j; } } std::vector<Field*> visited;
// push the field [4,5] in a visited vector
visited.push_back(maze[4][5]); // Clean up for(size_t i = 0; i < maze.size(); i++) { for(size_t j = 0; j < maze[i].size(); j++) delete maze[i][j]; }