From the sound of this, you really don't want a pointer. In fact, since this comes from the factory function in the C library, this is not a "first-class" C ++ pointer. For example, you cannot safely deletehim.
The real problem (if any) is to call SDL_FreeSurfaceit before the program exits.
-.
struct smart_sdl_surface {
SDL_Surface *handle;
explicit smart_sdl_surface( char const *name )
: handle( SDL_LoadBMP( name ) ) {}
~smart_sdl_surface()
{ SDL_FreeSurface( handle ); }
};
class ball
{
private:
static smart_sdl_surface ball_image_wrapper;
static SDL_Surface *& ball_image;
};
smart_sdl_surface ball::ball_image_wrapper( "ball.bmp" );
SDL_Surface *&ball::ball_image = ball::ball_image_wrapper.handle;
, . , .