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 6355631
In Process

The Archive Base Latest Questions

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

passing pointer to change its value but stay still I am working on C++

  • 0

passing pointer to change its value but stay still

I am working on C++ with allegro library.

there is draw_tiles function.

void draw_tiles(def_small_world * s_world,BITMAP * dest){
    BITMAP *TileMap=NULL; 

    loadTilemap(s_world->tilemap,TileMap); 
    for(int y = 0;y<SIGHTY*2+1;y++)
    {
        for(int x = 0;x<SIGHTX*2+1;x++)
        {
            pasteTile(s_world->tile[y][x].kind,TileMap,dest,x,y);
        }
    }

}

and loadTilemap function.

void loadTilemap(int i,BITMAP * tileLayer){
    char c[128];
    sprintf(c,TILEPATHFORMAT,i);
    tileLayer= load_bitmap(c,NULL);
}

I expect

following code change TileMap to points somewhere

loadTilemap(s_world->tilemap,TileMap); 

but after loadTilemap, the TileMap variable stay still.

the following code works very well

char c[128];
sprintf(c,TILEPATHFORMAT,i);
tileLayer= load_bitmap(c,NULL);

tileLayer points 0x003f93f8

How to fix my code to TileMap points return value of load_bitmap?

  • 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-24T22:48:19+00:00Added an answer on May 24, 2026 at 10:48 pm

    You are passing the pointer by value, so a copy of the pointer is created. Inside loadTilemap, you are assigning a new value to the copy of the pointer – but that doesn’t affect the original pointer.

    Try passing the pointer by reference by changing the loadTilemap function signature to this:

    void loadTilemap(int i,BITMAP *& tileLayer);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I don't understand why passing a pointer to a function doesn't change the data
What is the difference between passing-by-reference and using the C pointer notation? void some_function(some_type&
Is passing pointer argument, pass by value in C++? Since i see that any
Is it possible to change the value being pointed to by a FILE pointer
I'm trying to change a value in a multidimensional array but getting a compiler
gcc 4.6.2 c89 I am passing a pointer to a function. This pointer will
What are the benefits of passing by pointer over passing by reference in C++?
warning: passing argument 1 of 'bsearch' makes pointer from integer without a cast and
I have a pointer to a QScriptEngine that I'm passing through the overloaded class
I have an auto pointer class and in the constructor I am passing in

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.