I am using SDL2 to develop a C++ application and want to use shared_ptr to hold the pointer stuff. So i do e.g. this:
typedef std::shared_ptr<SDL_Window> SDLWindowPtr;
and i need to use a custom deleter on this whole thing. Is it possible to include this within the typedef? If yes, how? The deleting function is called SDL_DestroyWindow. If not, how can i make the shared_ptr use SDL_DestroyWindow as custom deletion function?
Thanks in advance!
Custom deleter is passed to shared_ptr in constructor, so it can't be done using typedef (deleter is not part of type of instantiated shared_ptr).
It could be done for unique_ptr (where deleter is part of type).
My suggestion: create factory method that will produce SDLWindowPtr (assigning them proper deleter). Something like std::make_shared but dedicated for your system (ex. createSDLWindow ?).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With