


Link (./765) :
PS: Il me semble que la référence const en général est une exception aux règles de scoping, pas seulement dans le contexte des traitements d'exception: Notamment, je crois me rappeler qu'une référence const vers un temporaire non-nommé étend sa durée de vie à celle de la référence.

try
{
m_screen(1024, 768, 32);
}class Screen
{
public:
Screen();
~Screen();
Screen(int width, int height, int bpp); // <==== Et ça c'est pour les chiens ?!?
SDL_Surface *getScreenPtr(void);
void update(void);
void setClip(SDL_Rect *Rect);
private:
Screen(const Screen&);
Screen operator= (const Screen&);
SDL_Surface *m_screen;
int m_width;
int m_height;
int m_bpp;
int m_flags;
};
Là tu va devoir faire m_screen.init(1024, 768, 32);

Task::Task() : m_currentTask(0), m_SDLState(false), m_screen()
{
try
{
m_screen.init(1024, 768, 32);
}
catch (ScreenException(exception))
{
fprintf(stderr, "%s\n", exception.getErrorString().c_str());
return;
}
m_SDLState = true;
}
int main (void)
{
try
{
Task MainTask;
return MainTask.ManageTask(TASK_INTRO);
}
catch(const ScreenException &exception)
{
fprintf(stderr, "%s\n", exception.getErrorString().c_str());
return EXIT_FAILURE;
}
}
Task::Task() : m_currentTask(0), m_SDLState(false), m_screen(1024, 768, 32)
{
/* ... */
}Folco (./796) :
Ici aussi, ne vaudrait-il pas mieux lancer une exception TaskException plutôt que de jouer avec un booléen, sur le même principe que pour Screen ?

#include <SDL.h>
#include "task.hpp"
#include "screen_except.hpp"
int main (void)
{
int ret = EXIT_FAILURE;
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) != 0)
{
fprintf(stderr, "Couldn't load SDL\n");
return ret;
}
try
{
Task MainTask;
ret = MainTask.ManageTask(TASK_INTRO);
}
catch (ScreenException const & exception)
{
fprintf(stderr, exception.getErrorString().c_str());
}
SDL_Quit();
return ret;
}Task::Task() : m_CurrentTask(0), m_MainScreen(1024, 768, 32)
{
}Screen:: Screen(int width, int height, int bpp) :
m_Screen(NULL), m_Width(width), m_Height(height), m_Bpp(bpp),
m_Flags(SDL_HWSURFACE | SDL_ANYFORMAT | SDL_DOUBLEBUF)
{
m_Screen = SDL_SetVideoMode(m_Width, m_Height, m_Bpp, m_Flags);
if (m_Screen == NULL)
{
m_Flags = SDL_SWSURFACE | SDL_ANYFORMAT;
m_Screen = SDL_SetVideoMode(m_Width, m_Height, m_Bpp, m_Flags);
if (m_Screen == NULL)
throw (ScreenException(SDL_GetError()));
}
}
)struct SDL_Rect {
Sint16 x, y;
Uint16 w, h;
// Constructeur
SDL_Rect(Sint16 x, Sint16 y, Uint16 w, Uint16 h)
{
this->x = x;
this->y = y;
this->w = w;
this->h = h;
}
};

JackosKing (./807) :
Ha les exceptions, ou la deresponsabilisation la plus totale....

JackosKing (./807) :
Et la liste d'init c'est un peu de la branlette de mamoutte pour pas grand chose, surtout dans ces cas!

Folco (./806) :
FYI : SDL_Rect m_offset = {offsetX, offsetY, width, height} marche très bien dans une méthode (et pas en liste d'init, et effectivement c'est très con)