Let say, that i have defined the same function for windows and mac, with different return values like this:
#ifdef _WIN32
// Windows code
int porting(int input){
return input + 360;
}
#endif
#ifdef __APPLE__
// Mac code
int porting(int input){
return input + 180;
}
#endif
Is there a way to allow the user to specify code to run inside porting(), instead of having multiple definitions?
C++, as a compiled language, has no
eval()function, which many interpreted languages (such as PHP or Javascript) have. There is no way to execute textual user-supplied code at runtime.Perhaps a callback would suffice for your needs?
Example: