<SOLVED> Inheritance and Pointers
Posted: Mon Mar 01, 2010 3:10 am
I'm and encountering an exception anytime I try to access an SDL_Surface* from a derived class. I have a console class:
And then I have the base class Object:
Basically, anytime my program tries to access myConsoleInstance->Frame , myConsoleInstance->image , myConsoleInstance->getRect()->x or anything like that I get an exception. I'm not sure what I'm doing wrong. Any help would be appreciated :D
Code: Select all
class Console: public Object
{ ////////////Only displaying members which may be relevant///////////////////
SDL_Surface* Frame;
vector<SDL_Surface*> textLines;
TTF_Font* font;
public:
Console(void);
void buildFrame();
SDL_Surface* getImage();
};
void Console::buildFrame() //Called by constructor. Made it a function so I could use it later when, say, the resolution was changed
{
SDL_Rect temp;
Uint32 color;
// Build the background
temp.h = SDL_GetVideoSurface()->h;
temp.w = SDL_GetVideoSurface()->w;
temp.x = 0;
temp.w = 0;
color = SDL_MapRGB( Frame->format , CONSOLE_BACKGROUND.r , CONSOLE_BACKGROUND.g , CONSOLE_BACKGROUND.b );
SDL_FillRect( Frame , &temp , color );
// Build the outline
temp.w = 4;
color = SDL_MapRGB( Frame->format , CONSOLE_FRAME.r , CONSOLE_FRAME.g , CONSOLE_FRAME.b );
SDL_FillRect( Frame , &temp , color );
temp.x = Frame->w - temp.w;
SDL_FillRect( Frame , &temp , color );
temp.w = Frame->w;
temp.x = 0;
temp.h = 4;
temp.y = Frame->h - 4 - 4 - 14;
SDL_FillRect( Frame , &temp , color );
temp.y = Frame->h - 4;
SDL_FillRect( Frame , &temp , color );
Object::image = Frame;
Object::rect.x = 0;
Object::rect.y = 0;
Object::rect.w = Frame->w;
Object::rect.h = Frame->h;
}
SDL_Surface* Console::getImage()
{
if( Frame != NULL )
return Frame;
else
return NULL;
}
Code: Select all
class Object
{
string imageName;
bool solid;
SDL_Rect collisionRect;
protected:
SDL_Rect rect;
SDL_Surface* image; /* Only used for Objects who cannot pre load their
images, IE: The Console */
public:
Object(void);
Object( int x , int y , const string& imageName = "" , int w = 0 , int h = 0 );
Object( int x , int y , int w = 0 , int h = 0 );
~Object(void);
void calculateMidpoint();
string* getImageName();
void setImageName( const string& newImageName );
SDL_Rect* getRect() ;
SDL_Surface* getSurface() ;
};