passing pointer to change its value but stay still

前端 未结 3 1369
臣服心动
臣服心动 2021-01-28 03:36

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_sm         


        
3条回答
  •  暖寄归人
    2021-01-28 04:08

    You need to pass a pointer to pointer to achieve that:

    void loadTilemap(int i,BITMAP ** tileLayer){
       char c[128];
       sprintf(c,TILEPATHFORMAT,i);
       *tileLayer= load_bitmap(c,NULL); 
    }
    
    loadTilemap(s_world->tilemap, &TileMap); 
    

    That's assuming TileMap is of type BITMAP *.

    Alternatively, you could simply return the BITMAP* pointer as a result of loadTilemap:

     BITMAP* loadTilemap(int i,BITMAP * tileLayer){
       char c[128];
       sprintf(c,TILEPATHFORMAT,i);
       return load_bitmap(c,NULL); 
    }
    
    TileMap = loadTilemap(s_world->tilemap, TileMap);
    

    This would allow you to get rid of tileLayer parameter altogether, as you don't seem to be using it for anything else in loadTileMap (i.e. it's only an output parameter).

提交回复
热议问题