我目前遇到了一个问题,需要将SDL_Window指针存储为std::unique_ptr。
我尝试的方法是:
std::unique_ptr<SDL_Window> window_;
解决方案:
std::unique_ptr<SDL_Window, void(*)(SDL_Window*)> window_;
第一次尝试在内存头文件中不断抛出错误,说SDL_Window是一个不完整的类型。我知道SDL_Window是一个结构体,不能被实例化。
SDL_Window* window_ = new SDL_Window();
因此,使用SDL_CreateWindow(params)进行实例化。 问题如下:
Why can't I call the default constructor (or any other) for SDL_Window?
Why does the unique_ptr needs a deleter in this case, but not here:
renderSystem_ = std::unique_ptr<Renderer::RenderSystem>(new Renderer::RenderSystem());
RenderSystem being a class with just a default constructor, destructor.
Is it because the unique_ptr can access the destructor, which acts as the deleter and doesn't need to come as a template argument?