title: A function that returns a function pointer for functions of different return types
body: <p>The context of this question revolves around hard typed genetic programming.</p>
  
  <p>I would like to return a function pointer from a function but these functions pointers point to functions with different return types. In another stack overflow question (<a href="https://stackoverflow.com/questions/28563015/function-pointers-with-different-return-types-c">Function Pointers with Different Return Types C</a>) a return type of union was suggested however I am struggling with the implementation.</p>
  
  <p>I am fairly new to C++ so please forgive my ignorance if it shows.</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string&gt;
  
  float Add(float a, float b) { return a + b; }
  bool IfElse(bool a) { if (a) { return true; } else { return false; }; }
  
  union return_type
  {
      float(*ffptr)(float, float);
      bool(*bfptr)(bool);
  };  
  
  union fptr(std::string OPERATION) {
      if (OPERATION == "Add") {
          return_type.ffptr = Add;
      } else if (OPERATION == "IfElse") {
          return_type.bfptr = IfElse;
      }
  
      return return_type;
  }
  
  int main() {
      std::cout &lt;&lt; fptr("Add") &lt;&lt; std::endl
      return 0;
  }
  </code></pre>
  
  <p>I expect (or rather would like) this to print the address of the function Add</p>