I am wondering how can I dynamically call class functions. Let's say I have a class '"dog", which contains function getname(), that returns name of that specific animal. But how could I call function dog::getname() like that but without the "dog" at the beginning I would use std::string animal = "dog", and then somehow do like animal::getname()
I haven't tried anything yet, because I simply have no idea how I could get similar result, or if it's even possible.
class dog {
public:
static std::string getname() {
return "Something";
}
}
class cat {
public:
static std::string getname() {
return "Something2";
}
}
std::string animal = "dog";
And now somehow call the function getname related to the animal which is in the string.