Hi!
I have two classes where the one is derived from the other - As you probably can see below:
class LevelObject : public Node
{
private:
// It helps to typedef super & self so if you change the name
// of the class or super class, you don't have to replace all
// the references
typedef Node super;
typedef LevelObject self;
protected:
b2Body* body;
Sprite* sprite;
public:
LevelObject();
void addBodyToWorld(b2World* world);
void addCircularFixtureToBody(float radius);
void addRectangularFixtureToBody(float width, float height);
void createFixture(b2Shape* shape);
void setProperties(ValueMap& properties);
virtual ~LevelObject();
};
class Player : public LevelObject
{
private:
protected:
b2Body* body;
Sprite* sprite;
b2World* world;
public:
void addBodyToWorld(b2World* world);
void addFixturesToBody();
};
As you can see the player is derived from LevelObject.
But then later on I make a function like:
LevelObject* Level::addObject(string className, ValueMap& properties)
{
// create the object
LevelObject* o = nullptr;
if (className == "Player")
o = new Player;
//o = new MagicChest;
// process the new object
if (o != nullptr)
{
o->setProperties(properties);
o->addBodyToWorld(this->world);
o->addFixturesToBody();
this->addChild(o);
}
return o;
}
Where I get an error that says: “LevelObject has no member named AddFixturesToBody()” but why?
I mean shouldn’t it be able to find the function created in the derived class or what should I do?
Btw, all tips are appreciated very much!
Thank you