I'm trying to make a game engine using Gameobject and Components, similar to Unity. I have a Component Class:
class Component
{
public:
virtual void DoTheThing(){//Doing the thing};
}
A Texture Class derived from Component, with an overridden function:
class Texture : public Component
{
public:
void DoTheThing(){//Doing a different thing};
}
A GameObject Class with a Component Map which stores derived components:
class GameObject
{
private:
map<string, Component> components;
Texture texture;
components["id"] = texture;
public:
Component getComponent(string id){ return components[id];}
}
And finally:
int main(int argc, char* args[])
{
GameObject gameObject;
gameObject.getComponent("id").DoTheThing();
}
What I want is to be able to call the DoTheThing() that exists in the derived class, but it only calls the DoTheThing() in the base class.