Tạo con trỏ tới cấu trúc SDL_Window và gán nó cho shared_ptr, kết quả lỗi được đề cập.Ứng dụng không hợp lệ 'sizeof' vào loại không đầy đủ 'SDL_Window'
Một phần của lớp:
#include <SDL2/SDL.h>
class Application {
static std::shared_ptr<SDL_Window> window;
}
Định nghĩa:
#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_);
}
Lỗi xuất hiện ở 'window.reset()'. Lý do và cách khắc phục hành vi này là gì?
Có lẽ không liên quan, nhưng bạn không cần phải deallocate qua SDL_DestroyWindow thay vì xóa? – PlasmaHH