Lets say we have a string named "pie" with the value of "do_something". We also have a function with the name of "do_something" Is there a way to call the function with the name of the value of pie? In this case, do_something?

There is a way to do this in PHP, but since C++ is a compiled language rather than an interpreted one, I have my doubts.

Not directly, but there are a couple work-arounds.

1) use a series of if statements to test the string value then call the function

if( pie == "do_something" )
   do_something();
else if(pie == "something_else" )
   something_else();
// etc etc for all string values

2) use <map> to map string values to function pointers.

3) create a structure that is something like 1) above. Useful if there are lots of functions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.