   SDL wrapper: private members
  Hello!I'm creating some classes based on SDL_Surface, one is 'Window' (it uses SDL_SetVideoMode) and the other is 'Texture'. Texture has a method 'show', which would apply its SDL_Surface to Window's, but I don't know how could it be done as Window's one is a private member (as it should be I think).It should sound confusing, so here is a piece of code:Window.hclass Window{private:SDL_Surface* screen;int width;int height;int bpp;bool windowed;bool ok;}Texture.cppint Texture::show(double x, double y,const Window* &window){...return SDL_BlitSurface(surface, &clipRect, window->screen /* error here */, &offset);}What do you recommend?   
  I suppose you also want to keep the Texture's surface private? One thing you could do is make Texture a friend of Window.class Window{friend class Texture;private:SDL_Surface* screen;int width;int height;int bpp;bool windowed;bool ok;};  SDL has a function that returns the window surfaceSDL_GetVideoSurface()http://www.libsdl.org/cgi/docwiki.cgi/SDL_GetVideoSurface;class Window{    ...    public:    SDL_Surface* getSurface(){return screen;}    ...};It's ok, it's just an accessor. It won't bite! [smile]   ;  Ugh. No.Question: Why does the Window have a 'SDL_Surface* screen?'Answer: Because things can be drawn within it.Thus, that is something the Window can do: draw things onto its screen. So, we make that part of the interface.Also, there is no point in passing a pointer by const-reference, since pointers are primitive types (i.e. just as easily passed by value). Also, pass things around by reference in your own code, and only create pointers when you have to in order to interface with SDL.int Window::draw(SDL_Surface& what, SDL_Point& where, SDL_Rect& clipRect) { // public  return SDL_BlitSurface(&what, &clipRect, screen, &where);}int Texture::show(double x, double y, Window& window) {  // ...  // Note that here I assume 'surface' is an SDL_Surface& rather than an  // SDL_Surface*. You might get that via a helper function, as illustrated below.  return window.draw(surface, offset, clipRect);}SDL_Surface& getSurfaceFromSDL(/* args */) {  SDL_Surface* result = SDL_API_call(args);  if (!result) { throw std::runtime_error("SDL API call failed."); }  return *result;}// Or better yet, use a smart pointer, or make some RAII wrapper.;Quote:Original post by ZahlmanAlso, there is no point in passing a pointer by const-reference, since pointers are primitive types (i.e. just as easily passed by value). Also, pass things around by reference in your own code, and only create pointers when you have to in order to interface with SDL.how can i show if there is an error without using the texture class as a pointer?   ;  The usual philosophy: if there was an error, such that you got a null pointer back from SDL, then you don't want to keep the object that would be storing that null pointer - throw an exception from its constructor, and handle that in the calling context.Sometimes it will be too difficult, or not appropriate. You can use boost::optional to represent things which are allowed not to be there; or you can sigh and stick with the pointer just for surfaces. But there is no reason to use pointers for, say, SDL_Rect, which you will not be creating with an API function or allocating dynamically.   