当创建一个指向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()'。这是什么原因,如何修复这种行为?