You should post some code so we can see exactly what is happening, but you're right that you shouldn't manually call the destructor because that will cause undefined behavior (see AliciaBytes' answer). Instead, add a method to the class to close the window, and use the class to provide a safe interface to the SDL window functions. Here is a sketch:
class Window {
private:
SDL_Window *window_;
public:
Window() : window_(nullptr) { }
Window(const Window &) = delete;
Window(Window &&w) : window_(w.window_) { w.window_ = nullptr; }
Window(const char* title, int x, int y, int w, int h, Uint32 flags)
: window(SDL_CreateWindow(title, x, y, w, h, flags))
{ }
~Window()
{
if (window_ != nullptr)
SDL_DestroyWindow(window_);
}
Window &operator=(const Window &) = delete;
Window &operator=(Window &&w)
{
if (window_) { SDL_DestroyWindow(window_); window_ = nullptr; }
window_ = w.window_;
w.window_ = nullptr;
}
operator bool() const
{
return window_ != nullptr;
}
void close()
{
if (window_ != nullptr) {
SDL_DestroyWindow(window_);
window_ = nullptr;
}
}
};