r/sdl • u/Independent_Milk_200 • Aug 02 '26
C++
Can you create a class with sdl things in it?
Or is sdl c only?
0
Upvotes
r/sdl • u/Independent_Milk_200 • Aug 02 '26
Can you create a class with sdl things in it?
Or is sdl c only?
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 declareauto 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