title: How to call a function by its name (std::string) in C++?
body: <p>I wonder if there is a simple way to call a function from a string. I know a simple way, using 'if' and 'else'.</p>
  
  <pre><code>int function_1(int i, int j) {
      return i*j;
  }
  
  int function_2(int i, int j) {
      return i/j;
  }
  
  ...
  ...
  ...
  
  int function_N(int i, int j) {
      return i+j;
  }
  
  int main(int argc, char* argv[]) {
      int i = 4, j = 2;
      string function = "function_2";
      cout &lt;&lt; callFunction(i, j, function) &lt;&lt; endl;
      return 0;
  }
  </code></pre>
  
  <p>This is the basic approach</p>
  
  <pre><code>int callFunction(int i, int j, string function) {
      if(function == "function_1") {
          return function_1(i, j);
      } else if(function == "function_2") {
          return function_2(i, j);
      } else if(...) {
  
      } ...
      ...
      ...
      ...
      return  function_1(i, j);
  }
  </code></pre>
  
  <p>Is there something simpler?</p>
  
  <pre><code>/* New Approach */
  int callFunction(int i, int j, string function) {
      /* I need something simple */
      return function(i, j);
  }
  </code></pre>