I'm trying to use unique_ptr
in cpp with SDL_Window
, but it's an incomplete type, after I get the first error trying to compile the code, I created my own deleter struct, but it still not working, so here is how I'm trying:
struct SDLWindowDeleter{
void operator()(SDL_Window* window) {
SDL_DestroyWindow(window);
}
};
and here is the creation of the window:
std::unique_ptr<SDL_Window, SDLWindowDeleter>
Initializer::create(Uint32 w, Uint32 h, std::string title) {
std::unique_ptr<SDL_Window, SDLWindowDeleter> window;
startSDL();
window = std::unique_ptr<SDL_Window, SDLWindowDeleter>
(SDL_CreateWindow(title.c_str(), 0, 0, w, h, SDL_WINDOW_OPENGL));
return window;
}
and to receive the window i use:
window = std::move(Initializer::create(500, 500, "Title"));
the compiler's errors is:
Error 1 error C2027: use of undefined type 'SDL_Window' c:\program files\microsoft visual studio 12.0\vc\include\memory 1198 1 game
Error 2 error C2338: can't delete an incomplete type c:\program files\microsoft visual studio 12.0\vc\include\memory 1199 1 game
Error 4 error C2679: binary '=' : no operator found which takes a right-hand operand of type 'SDLWindowDeleter' (or there is no acceptable conversion) c:\program files\microsoft visual studio 12.0\vc\include\memory 1424 1 game
This third error I can't understand why, because if it's a struct, don't need to overload the binary operand '='.
Should I use a "non-safe" pointer? or there exists some way to fix this error?