Skip to main content
GameDev.net gamedev.net
🔒 Locked

Class Polymorphisms problem

Started by shadow320 Aug 10, 2010 at 11:37 AM 5 replies 950+ views
Original Post
shadow320
shadow320
Hello, I have a huge problem, I'm writing a game using SDL and I've made it almost but I got into trouble with using class polymorphisms. The thing is that I am creating state machine and I've seperated my classes in .h files. When I'm trying to use a class like including them in other .h file with a class derivative to a base class and I'm compiling it I get no errors, but when I run it, I get an Send report or Don't send message.

This is a piece of one of the .h files where I want to include CPLayer.h and compile i get the message

#ifndef CMENU_H
#define CMENU_H

#include "CGameState.h"
#include "CPlayer.h"
#include "Globals.h"
#include "Functions.h"
dmatter
dmatter
Quote:
Original post by shadow320
I'm compiling it I get no errors, but when I run it, I get an Send report or Don't send message.
The send or don't send happens because of a runtime error, your program compiles and links fine (which means your header files are included ok) but crashed because of something your program is trying to do - maybe trying to access a null pointer or something. Are you not running it in debug mode or as a debug build?.. Perhaps not running it through the IDE at all?
serratemplar
serratemplar
dmatter is right; likely your inclusion structure is not the issue. Can we see an example of a class or two that you're using here? What flavor of c++ are you using (i.e. g++, vs10)?

We need more to go on to help you.
shadow320
shadow320
Thank you for trying to help me. I work with Dev C++ and SDL. But I am doubting that it's not from the basic classes for the player and the enemy, because they worked fine before I create the code for the menu. If I use only the menu is OK but when i write the code for switching from the menu to the level and then the message starts to show. Here is the sample of the code. And again many thanks.
Sorry I don't know how to put tab in the post :(

#ifndef CMENU_H
#define CMENU_H

#include "CGameState.h"
#include "CPlayer.h"
#include "Globals.h"
#include "Functions.h"

//Class Menu;
CMenu::CMenu()
{
titleY = 480;
menuChoise = 1;
menuActive = false;
bgIMG = Load_IMG("Images\\background_img.png");
titleIMG = Load_PNG("Images\\title.png");
menuFont = TTF_OpenFont("Fonts\\spcinv_font.ttf", 32);
}
CMenu::~CMenu()
{
SDL_FreeSurface(bgIMG);
SDL_FreeSurface(titleIMG);
TTF_CloseFont(menuFont);
}

//Class World;
CWorld::CWorld()
{
bgIMG = Load_PNG("Images\\background_img.png");
Tank.SetClips();
}
CWorld::~CWorld()
{
SDL_FreeSurface(bgIMG);
}
void CWorld::handle_events()
{
while(SDL_PollEvent(&Events))
{
if(Events.type == SDL_QUIT)
{
Set_Next_State(STATE_EXIT);
}
Tank.KeyHandle();
}
}
void CWorld::logic()
{
Tank.Move();
}
void CWorld::render()
{
Apply_Surface(0,0,bgIMG,Screen);
Tank.Show();
}
#endif
Zakwayda
Zakwayda
You can use [ source ] tags (no spaces) to post your code with (in most cases) proper formatting.
dmatter
dmatter
Quote:
Original post by shadow320
Thank you for trying to help me. I work with Dev C++ and SDL.
Ah, well, there's your first mistake. Get yourself a 100% free copy of Visual C++ 2010 Express rather than that ancient DevC++ rubbish. If you're a student you can even get the Professional Edition for free.

Once you have that setup, start a new project, get your code moved across & SDL configured; and then have a go at running it. If there's a problem then the debugger should step in and give you some indication of where things went wrong.

Quote:
If I use only the menu is OK but when i write the code for switching from the menu to the level and then the message starts to show.
What does the code that performs the switch look like?
shadow320
shadow320
OK guys I am downloading Microsoft Visual Studio 2008 because the 2010 require Service Pack 3. But I've always thought that this is only a 30 days trial. I've found where was the problem with the Don't Send message it was within the CPlayer file. In the constructor of Player class I give the X, Y, H, W a values different than 0 and this was making the problem, now I am giving them prime init and everything is set to 0. Now I don't have that problem. I declare Player object within the CWorld class and is OK but when I need to init the player object within the constructor of the CWorld class I get this error: insufficient contextual information to determine type.

And again I am sorry for the mess of the post.

This is sample from the new Player class:
class Player
{
public:
SDL_Surface *plSprite;
SDL_Rect Body;
SDL_Rect plClips[4];
Timer pTimer;
int Lifes, plFrame;
bool alive, dead;
Player();
~Player();
void plInit(int x, int y, int h, int w, bool first, bool sec);
void SetClips();
void Show();
void KeyHandle();
void CollHandle();
void Move();
};
Player::Player()
{
plInit(0,0,0,0,false,true);
plSprite = Load_PNG("Images\\tank_spr.png");
}
Player::~Player()
{
SDL_FreeSurface(plSprite);
}

And this is a sample of the World class:
class CWorld : public GameState
{
private:
SDL_Surface *bgIMG;
Player Tank();
public:
CWorld();
~CWorld();
virtual void handle_events();
virtual void logic();
virtual void render();
};
CWorld::CWorld()
{
bgIMG = Load_PNG("Images\\background_img.png");
Tank.plInit(300,200,44,26,true,false); //This is the problem line
}
CWorld::~CWorld()
{
SDL_FreeSurface(bgIMG);
}

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.