IGNORE ALL THIS, Go to my second comment
Hiiiiiii, I'm having an issue accessing members of a class from its parent, I know it can be done using virtual members something like this:
class A
{
virtual void doSomething ( void ) { }
};
class B : A
{
virtual void doSomething ( void )
{
dbPrint ( "12341234" );
}
}
but I cant get it to work.
I'm on half making a final fantasy type RPG and I'm trying to get the fight scene done.
I've got an EnemyClass that has all the variables such as level, hp, mp and then child classes for each type of enemy which will have functions such as load_object, kill etc.
I will have an array EnemyClass enemies[3] and I create the 3 child classes and assign them to 0, 1 and 2 then from a "start_fight" function I want to be able to do something like enemies[1]->load_object() but it always calls the load_object from the EnemyClass and not the child.
Quite complicated I know
any ideas how to get it to work or an example?
Thanks, Mal
Edit:
I just did this quick test:
#include "DarkGDK.h"
class A
{
public:
virtual void doPrint ( void )
{
dbText ( 10, 10, "A::doPrint" );
}
};
class B : public A
{
public:
virtual void doPrint ( void )
{
dbText ( 10, 10, "B::doPrint" );
}
};
class C : public A
{
public:
virtual void doPrint ( void )
{
dbText ( 10, 10, "C::doPrint" );
}
};
A* bc[2];
void DarkGDK ( void )
{
dbSyncRate ( 60 );
B b;
C c;
bc[0] = &b;
while ( LoopGDK ( ) )
{
bc[0]->doPrint ( );
dbSync ( );
}
return;
}
and it works fine, but in my other version it doesn't
I would post the code but there's hundreds of lines so I'll take another look, if I get desperate I'll put the code up.
Edit 2:
I figured out why I was having a problem, I was creating the "Guard" class in a function and assigning it to "Fight::Enemies[]" from there so once the function was done the pointer to the classes I was giving it don't work, declaring them outside worked but that would mean they always exist even if I don't want them
oh well I'll figure something out
Don't make war, make tea.