#include <map>
typedef void(*function)(void*);
std::map<std::string, function> funcmap;
void doCreate(void *_args){
//intended to be passed a string, testing using Void* and string casting.
std::string strVal = *(std::string *)_args; //if breakpointed, strVal == Str1.
if (strVal == "Str1") //as strVal == Str1 this is true.
fprintf(stdout, "Str1 is set but it = %s\n", strVal.c_str()); //output is: "Str1 is set but it = <unicode characters>"
fprintf(stdout, "value = %s\n", strVal.c_str()); //output is the same as above: "value = <unicode characters>"
}
void functionRun(std::string s){
std::string strings;
strings = "Str1";
(*funcmap.at(s))(&strings);
}
int main(){
funcmap["onCreate"] = doCreate;
functionRun("onCreate");
}
I2luY2x1ZGUgPG1hcD4KCnR5cGVkZWYgdm9pZCgqZnVuY3Rpb24pKHZvaWQqKTsKc3RkOjptYXA8c3RkOjpzdHJpbmcsIGZ1bmN0aW9uPiBmdW5jbWFwOwoKdm9pZCBkb0NyZWF0ZSh2b2lkICpfYXJncyl7CiAgICAvL2ludGVuZGVkIHRvIGJlIHBhc3NlZCBhIHN0cmluZywgdGVzdGluZyB1c2luZyBWb2lkKiBhbmQgc3RyaW5nIGNhc3RpbmcuCglzdGQ6OnN0cmluZyBzdHJWYWwgPSAqKHN0ZDo6c3RyaW5nICopX2FyZ3M7IC8vaWYgYnJlYWtwb2ludGVkLCBzdHJWYWwgPT0gU3RyMS4KCQoJaWYgKHN0clZhbCA9PSAiU3RyMSIpIC8vYXMgc3RyVmFsID09IFN0cjEgdGhpcyBpcyB0cnVlLgoJCWZwcmludGYoc3Rkb3V0LCAiU3RyMSBpcyBzZXQgYnV0IGl0ID0gJXNcbiIsIHN0clZhbC5jX3N0cigpKTsgLy9vdXRwdXQgaXM6ICJTdHIxIGlzIHNldCBidXQgaXQgPSA8dW5pY29kZSBjaGFyYWN0ZXJzPiIKCglmcHJpbnRmKHN0ZG91dCwgInZhbHVlICA9ICVzXG4iLCBzdHJWYWwuY19zdHIoKSk7IC8vb3V0cHV0IGlzIHRoZSBzYW1lIGFzIGFib3ZlOiAidmFsdWUgPS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