将 SDL_Cursor 与 unique_ptr 一起使用:不允许错误类型不完整
Using SDL_Cursor with unique_ptr : error incomplete type is not allowed
我正在尝试创建类型为 SDL_Cursor
的 unique_ptr
,但我无法这样做,因为 SDL_Cursor
定义在 SDL 的一个 .dll 文件中。
已声明 SDL_Cursor 结构但未在 SDL_mouse.h 中定义:
typedef struct SDL_Cursor SDL_Cursor;
所以我一直收到错误消息:
E0070 incomplete type is not allowed
use of undefined type 'SDL_Cursor'
有没有办法从.dll文件中提取SDL_Cursor
的定义来避免这个错误?
这是我尝试过的:
#include <memory>
#include "SDL.h"
SDL_Cursor* p = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW); - How it is usually created
SDL_Cursor* p = new SDL_Cursor(); - Undefined type error.
std::unique_ptr<SDL_Cursor> unique = std::unique_ptr<SDL_Cursor>(new SDL_Cursor()); - Undefined type error.
我知道我也会为 unique_ptr
提供自定义删除器 (SDL_FreeCursor
),但由于这个错误,即使这样目前也不起作用。
如何获得SDL_Cursor
的定义?
您不想让 SDL 隐藏类型的原因有多种。即使你明白了,它可能会在未来的 SDL 版本中发生变化,即使在那种情况下 new
ing 游标也无济于事。在任何情况下,使用 SDL creation/destruction 函数,例如:
std::unique_ptr<SDL_Cursor, decltype(&SDL_FreeCursor)> p = {SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW), SDL_FreeCursor};
我正在尝试创建类型为 SDL_Cursor
的 unique_ptr
,但我无法这样做,因为 SDL_Cursor
定义在 SDL 的一个 .dll 文件中。
已声明 SDL_Cursor 结构但未在 SDL_mouse.h 中定义:
typedef struct SDL_Cursor SDL_Cursor;
所以我一直收到错误消息:
E0070 incomplete type is not allowed
use of undefined type 'SDL_Cursor'
有没有办法从.dll文件中提取SDL_Cursor
的定义来避免这个错误?
这是我尝试过的:
#include <memory>
#include "SDL.h"
SDL_Cursor* p = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW); - How it is usually created
SDL_Cursor* p = new SDL_Cursor(); - Undefined type error.
std::unique_ptr<SDL_Cursor> unique = std::unique_ptr<SDL_Cursor>(new SDL_Cursor()); - Undefined type error.
我知道我也会为 unique_ptr
提供自定义删除器 (SDL_FreeCursor
),但由于这个错误,即使这样目前也不起作用。
如何获得SDL_Cursor
的定义?
您不想让 SDL 隐藏类型的原因有多种。即使你明白了,它可能会在未来的 SDL 版本中发生变化,即使在那种情况下 new
ing 游标也无济于事。在任何情况下,使用 SDL creation/destruction 函数,例如:
std::unique_ptr<SDL_Cursor, decltype(&SDL_FreeCursor)> p = {SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW), SDL_FreeCursor};