Search code examples
c++sdlunique-ptrhandle

Using SDL_Cursor with unique_ptr : error incomplete type is not allowed


I am trying to create a unique_ptr of type SDL_Cursor, but am unable to do so as the SDL_Cursor definition is within one of SDL's .dll files.

The SDL_Cursor struct is declared but not defined in SDL_mouse.h:

typedef struct SDL_Cursor SDL_Cursor;

So I keep getting the error:

E0070 incomplete type is not allowed

use of undefined type 'SDL_Cursor'

Is there any way to extract the definition of SDL_Cursor from the .dll file to avoid this error?

Here is what I have tried:

#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.

I am aware I would provide a custom deleter (SDL_FreeCursor) to the unique_ptr aswell, but even that doesn't work at present due to this error.

How can I get the definition of SDL_Cursor?


Solution

  • There are multiple reasons you don't really want to get types SDL hides from you. Even if you get that, it may change in future SDL version, and even in that case newing cursor achieves nothing. In any case, use SDL creation/destruction functions, e.g.:

    std::unique_ptr<SDL_Cursor, decltype(&SDL_FreeCursor)> p = {SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW), SDL_FreeCursor};