I want to use string value to call a function. Is this possible? Can someone please show some implementation. I would appreciate it.
class obj {
int num1;
int num2;
}
int func1(obj o) {
return o.num1 + o.num2;
}
std::map<std::string, std::string> funcNameMap = ;
int someFunction(std::string funcName, obj o) {
// Get the value associated with the string "funcName" i.e. "func1".
// Calls function "func1" with value "o" and returns the value.
}
int main(){
obj o;
o.num1 = 1;
o.num2 = 2;
auto x = someFunciton("func1", o);
std::cout << x << std::endl;
return 0;
}
Aucun commentaire:
Enregistrer un commentaire