fex
fex

Reputation: 3558

"Connecting" SDL_Surface to shared_ptr

I'd like to know how can I connect SDL_Surface* with shared_ptr?
I need to call SDL_FreeSurface(SDL_Surface*) before I delete SDL_Surface. How can I "modify deletion process" in shared_ptr?

Upvotes: 6

Views: 728

Answers (1)

Benjamin Lindley
Benjamin Lindley

Reputation: 103751

Just pass SDL_FreeSurface to the constructor:

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

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

Upvotes: 13

Related Questions