创建指向 SDL_Window 结构的指针并将其分配给 shared_ptr,导致上述错误。
部分课程:
#include <SDL2/SDL.h>
class Application {
static std::shared_ptr<SDL_Window> window;
}
定义:
#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_);
}
错误出现在“window.reset()”中。是什么原因以及如何解决此行为?