Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7036275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:24:17+00:00 2026-05-28T01:24:17+00:00

i have to implement a small and simple game in c++ (a maze) and

  • 0

i have to implement a small and simple game in c++ (a maze) and I have some problems right now.

Some snippets:
I’ve got an array of object pointers which represents my fields in the maze

Field*** maze;

init of the maze:

for (n = 0; n < MAZE_WIDTH; n++) {
    this->maze[n] = new Field*[MAZE_HEIGHT];
    for (p = 0; p < MAZE_HEIGHT; p++) {
        this->maze[n][p] = new Field();
        this->maze[n][p]->x = n;
        this->maze[n][p]->y = p;
    }
}

When creating the maze i need a list of already visited fields and a stack
so I did:

std::vector<Field*> visited;
std::vector<Field*> stack;

Then later I want to put a Field* into my stack

stack.push_back(neighbour);

But after this push all values in the object are wrong.
Even if i try

neighbour = stack.back();

all the values are completly different

I already red some threads about this topic and that’s why i chose a vector of pointers and not objects.

Where is my fault?

Edit:
Some more snippets as requested:

Of course I allocate memory for the mate itself

this->maze = new Field**[MAZE_WIDTH];

Field is a simple class which looks like:

class Field {
public:
    Field();
~Field();
bool w_left;
bool w_right;
bool w_front;
bool w_back;
unsigned int x;
unsigned int y;
private:
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:24:17+00:00Added an answer on May 28, 2026 at 1:24 am

    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];      
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working to implement some simple preferences to an app I have and
I have to implement a one linked list but it should put object in
I have found that I often have to implement some sort of a scheduler
I'm attempting to implement a Save/Load feature into my small game. To accomplish this
I have a simple iPhone app which accesses some remote data on start-up then
I have a simple question for you. I need to implement the list of
I have been developing a simple game for iOS which involves dragging and using
I'm looking to implement fuzzy search for a small PHP/MySQL application. Specifically, I have
I am working in a small educational project where we have to implement a
I have a simple solid modeling application in which I want to implement several

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.