Quantcast
Channel: Cocos Forums - Latest topics
Viewing all articles
Browse latest Browse all 17119

Function not found from derived class?

$
0
0

@nichlaspro132 wrote:

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

Posts: 4

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 17119

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>