c++ help

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
bappy
Posts: 63
Joined: Fri Dec 12, 2003 10:49 am
Location: france
Contact:

c++ help

Post by bappy »

i just would like to have some help on c++.

here is the deal:

class BASE
{
BASE()
~BASE;
virtual void Affiche()=0;
};

class PLAYER: public Base
{
PLAYER();
~PLAYER()
void Affiche(){...};
void ShootGrenade(){...};
}

class OBJET: public Base
{
OBJET();
~OBJET()
void Affiche(){...};
void Update(){...};
}


class LEVEL
{
BASE *Player;
BASE *Objet;
void Init();
}

now in init i want to do that:
void LEVEL::Init()
{
Player = new PLAYER();
Objet = new OBJET();
// -- that s working but when i do that:
Player->ShootGrenade();
// -- it s says : Shootgrenade is not a member of BASE

}

so i don t know how to say to the compiler that finally player is not a base but is a player :?
-----------------------------
Sans danger, pas de gloire...
http;//bappy.free.fr
-----------------------------
darkliquid
Posts: 41
Joined: Sun Nov 09, 2003 10:12 am
Location: UK
Contact:

Re: c++ help

Post by darkliquid »

bappy wrote: class LEVEL
{
BASE *Player;
BASE *Objet;
void Init();
}

now in init i want to do that:
void LEVEL::Init()
{
Player = new PLAYER();
Objet = new OBJET();
// -- that s working but when i do that:
Player->ShootGrenade();
// -- it s says : Shootgrenade is not a member of BASE

}

so i don t know how to say to the compiler that finally player is not a base but is a player :?
what you have done is declare the your pointer to the the player object as a BASE type

Code: Select all

BASE *Player;
this means you can only access it using methods defined in the base class, as that is the interface you have requested, what class Level shoudld be is:

Code: Select all

class LEVEL
{
PLAYER *Player;
OBJET *Objet;
void Init();
}
you can still use the base class methods as both these classes inherit from it

Well, I think that's right :)
http://www.darkliquid.net - Blog, art, poetry
deps
Posts: 115
Joined: Sat Jan 10, 2004 5:22 pm
Location: Tranås, Sweden

Post by deps »

I think this is what you are looking for,
http://www.gamleby.net/gearhead/index.p ... les&view=1
The example is written for the 2D library Allegro, but it explains really well how to create a class from another class, and how to iterate them and other stuff.
Post Reply