jeudi 6 septembre 2018

Step down pointer type a level for use with shared_ptr

Im refactoring my SDL2 code to make use of some of the new functionalities with c++11 and letting some shared_ptr handling the cleanup. Then I stumbled upon this problem. Now i write this, when creating a openGL context.

auto window = shared_ptr<SDL_Window>(SDL_CreateWindow(
        "Opengl stuff", 0, 0, width, height, windowFlags),
        SDL_DestroyWindow);


auto context = shared_ptr<void>(
        SDL_GL_CreateContext(window.get()),
        SDL_GL_DeleteContext);

The problem is when I want to assign to the variable context, i cannot find the right thing to write in the brackets of shared_ptr (void in the code above).

typedef struct SDL_Window SDL_Window;
typedef void *SDL_GLContext;

I would really want it in the same form as `shared_ptr, but since SDL_GLContext is of a pointer type it is not possible. You can see that what i've done is using void as a type, but if I want the type to be visible, how can i "change the level" of the pointer type to be of non pointer type? I know how to do it for variables, but how do I do it with types?

Aucun commentaire:

Enregistrer un commentaire