I got the following code from code review which has been confusing me for a while.
class Window {
public:
Window(int x, int y, int w, int h, bool fullScreen = false) {
pWindow = SDL_CreateWindow("", x, y, w, h, fullScreen);
if (pWindow == nullptr)
throw std::runtime_error("Unable to create window");
}
~Window() { SDL_DestroyWindow(pWindow); }
operator SDL_Window*() { return pWindow; }
private:
SDL_Window *pWindow;
};
I am interested in line operator SDL_Window*() { return pWindow; }
. The result of this line is that any instance of this class actually refers to the pWindow
variable (a struct) that holds the actual SDL window (I have tested an verified this). But how. How does overloading SDL_Window*
operator cause the instance of that class to return pWindow
, when it makes more sense to overload the actual Window
class (if that even is a thing).
I don' even understand what it means to overload SDL_Window*
in this context.