"Connecting" SDL_Surface to shared_ptr

I would like to know how can I connect SDL_Surface * with shared_ptr?
I need to call SDL_FreeSurface(SDL_Surface*) before I remove SDL_Surface . How can I "change the delete process" in shared_ptr?

+6
source share
1 answer

Just pass SDL_FreeSurface to the constructor:

 std::shared_ptr<SDL_Surface> shared_surf(SDL_LoadBMP("foo.bmp"), SDL_FreeSurface); 

Just make sure you don't do this with the pointer returned by SDL_SetVideoMode or SDL_GetVideoSurface .

+13
source

Source: https://habr.com/ru/post/912342/


All Articles