I'm trying to use unique_ptr
with a custom deleter for SDL_Surface
type. This is only an example using int
type, but I hope you get the idea.
#include <iostream>
#include <functional>
#include <memory>
typedef int SDL_Surface;
SDL_Surface * CreateSurface()
{
SDL_Surface * p = new SDL_Surface;
return p;
}
void FreeSurface(SDL_Surface *p)
{
delete p;
}
int main() {
std::unique_ptr<SDL_Surface, std::function< void (SDL_Surface *) > > uptr_1;
//how to assign a value to uptr_1 and the deleter?
return 0;
}
Is uptr_1
correctly declared and initialized to nullptr
? If so, how can I assign the pointer and the deleter function?
And how can I encapsulate this:
std::unique_ptr< SDL_Surface, std::function< void (SDL_Surface *) > >
with the deleter to not always write that line on every SDL_Surface
I want, another typedef?
I'm just starting to learn C++11 features and this is a hard one for me.