Class organization
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 &'
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:
Which means you should be using a reference.
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.
To clarify ToohrVyk's advice (and add my own by example):
(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.)
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.)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement