I have this code where I am trying to return a component which is a base class that is inherited by many different "components". I want to then use this 'getComponent' method to call a function specific to that inherited component. Is there any way to do this?
Component& GameObject::getComponent(const std::string &name)
{
for(Component* c : components){
std::cout << c->name << std::endl;
if(c->name == name){
return *c;
}
}
throw std::invalid_argument( "GameObject does not have Component: " + name);
}