Sign in to follow this  
ConorH

Class organization

Recommended Posts

I have a 3 classes, Graphics Handles all SDL init, loading and drawing stuff. It also holds the pointer to the screen and the format of it. Engine Puts Graphics and all other sub systems into one more managable class Sprite A Class for displaying animated images essentially, but more for having a tangible object that relates to an image on the screen. It has x and y values, for its position on screen etc. How would I use pointers to access the member funcs and variables of cGfx from within cSprite? For instance; SDL_Surface* cSprite::SpriteLoadImage(cGfx* GraphicsPointer, const char* im) { return GraphicsPointer -> LoadImage(im) } This doesnt seem to work: cannot convert parameter 1 from 'SDL_Surface *' to 'const SDL_Surface &'

Share this post


Link to post
Share on other sites
There is no place in the provided code where that error could have appeared. Please post the place in your code where the error occured (or the code that defines cGfx, if for some reason it is a smart pointer around a SDL_Surface).

You are using cGfx pointers correctly, the error has nothing to do with them. Well, almost correctly; you're passing a pointer, but:
  • The function does not have a particular meaning associated to a null pointer being passed.
  • The function does not check the pointer for nullity either.

Which means you should be using a reference.

Share this post


Link to post
Share on other sites
To clarify ToohrVyk's advice (and add my own by example):


SDL_Surface* Sprite::LoadImage(Graphics& graphics, const std::string& name) {
return graphics.LoadImage(name.c_str());
}


(Except that similar changes would probably need to propagate through the system. For example, the .c_str() should only happen at the point where you actually call an SDL function, as opposed to one of your own.)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this