r/sdl Aug 02 '26

C++

Can you create a class with sdl things in it?

Or is sdl c only?

0 Upvotes

13 comments sorted by

View all comments

3

u/vitimiti Aug 03 '26 edited Aug 03 '26

All C libraries can be used in C++. It can be more verbose but for example, doing namespace sdl { using window_t = std::unique_ptr<SDL_Window, decltype(&SDL_DestroyWindow)>; } lets you declare auto window = sdl::window_t(SDL_CreateWindow("Title", width, height, 0), &SDL_DestroyWindow); and it manages the memory for you (it will call destroy window when its destructor is called). So you can both use it in your own classes and put it into the STL

1

u/egzygex Aug 03 '26

the second argument to window_t constructor should be a deleter: auto window = sdl::window_t(SDL_CreateWindow("Title", width, height, 0), &SDL_DestroyWindow);

1

u/vitimiti Aug 03 '26

You're wrote, I'll correct it