Invalid application of 'sizeof' to incomplete type 'SDL_Window'

c++, sdl, shared-ptr, struct

Solution

By default, `shared_ptr` will release the managed resource using `delete`. However, if you're using a resource that needs releasing another way, you'll need a custom deleter:

window.reset(window_, SDL_DestroyWindow);

NOTE: I'm fairly sure this will work, but I don't have an SDL installation to test it with.

Problem

Creating a pointer to an SDL_Window struct and assigning it to a shared_ptr, the mentioned error results. Part of the class: ``` #include <SDL2/SDL.h> class Application { static std::shared_ptr<SDL_Window> window; } ``` Definition: ``` #include "Application.h" std::shared_ptr<SDL_Window> Application::window{}; bool Application::init() { SDL_Window *window_ = nullptr; if((window_ = SDL_CreateWindow(title.c_str(), SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, window_width, window_height, NULL) ) == nullptr) { std::cerr << "creating window failed: " << SDL_GetError() << std::endl; } window.reset(window_); } ``` The error appears at 'window.reset()'. What is the reason and how to fix this behavior?

Original source