?
class car {
public:
void go(){
}
}
int main() {
string method="go";
car bmw;
//now how to call go with method variable?
return 0 ;
}
This is not directly possible in C++. C++ is a compiled language, so the names of functions and variables are not present in the executable file - so there is no way for the code to associate your string with the name of a function. https://stackoverflow.com/questions/18442101/calling-a-function-using-a-string-containing-the-functions-name
Tldr: don't Real answer : you need to reproduce the mangling algorithm of your compiler, then you need to explore your executable to find the entry point of the function, then call it with a pointer to your object on top of the stack or wherever applicable for your specific compiler
Обсуждают сегодня