passing pointer to change its value but stay still

前端 未结 3 1368
臣服心动
臣服心动 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:14

    Try this:

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

    The problem was that you pass the pointer to the BITMAP by value. To get the new pointer value out of loadTilemap, you have to pass it by reference.

    EDIT:

    On the other hand: why don't you just return the pointer to the newly created BITMAP?

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

提交回复
热议问题