fork(2) download
  1. #include <map>
  2.  
  3. typedef void(*function)(void*);
  4. std::map<std::string, function> funcmap;
  5.  
  6. void doCreate(void *_args){
  7. //intended to be passed a string, testing using Void* and string casting.
  8. std::string strVal = *(std::string *)_args; //if breakpointed, strVal == Str1.
  9.  
  10. if (strVal == "Str1") //as strVal == Str1 this is true.
  11. fprintf(stdout, "Str1 is set but it = %s\n", strVal.c_str()); //output is: "Str1 is set but it = <unicode characters>"
  12.  
  13. fprintf(stdout, "value = %s\n", strVal.c_str()); //output is the same as above: "value = <unicode characters>"
  14. }
  15.  
  16. void functionRun(std::string s){
  17. std::string strings;
  18. strings = "Str1";
  19. (*funcmap.at(s))(&strings);
  20. }
  21.  
  22. int main(){
  23. funcmap["onCreate"] = doCreate;
  24. functionRun("onCreate");
  25. }
Success #stdin #stdout 0s 3480KB
stdin
Standard input is empty
stdout
Str1 is set but it = Str1
value  = Str1