Here it is:
SDLAutoInit.h
Code: Select all
/************************************************************************
* SDLAutoInit.h
*
* SDLAutoInit class is used to make sure that SDL_Quit()
* gets called, because it gets called automatically in the
* destructor.
*
* There is currently no private data in this class.
*
* Author: Miguel Martin.
*************************************************************************/
#pragma once
#include <SDL.h>
class SDLAutoInit
{
public:
SDLAutoInit(void); // Default Constructor, does nothing.
SDLAutoInit(Uint32 flags); // Custom constructor, calls Init
~SDLAutoInit(void); // Destuctor, calls Quit()
int Init(Uint32 flags); // Calls SDL_Init(Uint32 flags)
void Quit(); // Calls SDL_Quit().
};
Code: Select all
#include "SDLAutoInit.h"
SDLAutoInit::SDLAutoInit(void)
{
// Does nothing...
}
SDLAutoInit::SDLAutoInit( Uint32 flags )
{
// Call's Init();
Init(flags);
}
SDLAutoInit::~SDLAutoInit(void)
{
// Call's Quit.
Quit();
}
int SDLAutoInit::Init( Uint32 flags )
{
int error = 0;
if((error = SDL_Init(flags)) == -1){
fprintf(stderr, "[ERROR]: SDL_Init(Uint32); failed: %s.\n", SDL_GetError());
}
return error;
}
void SDLAutoInit::Quit()
{
SDL_Quit();
}