title: C++ How to get a void pointer to a lambda function?
body: <p>I can't even type example code... pretty lost. Here's my original function which is NOT a lambda function (I want it to be lambda).</p>
  
  <pre><code>static void* DoublePointer(void** arg, int arg_sz) {
      double* n1 = In(arg[0]);
      double* n2 = In(arg[1]);
      double* n3 = In(arg[arg_sz-1]);
  
      *n3 = *n1 + *n2;
  
      return n3;
  }
  
  void* func_ptr = DoublePointr; //works fine
  </code></pre>
  
  <p>But what I really want is this:</p>
  
  <pre><code>my_class.save_the_func = [](void** arg, int arg_sz) {
      double* n1 = In(arg[0]);
      double* n2 = In(arg[1]);
      double* n3 = In(arg[arg_sz-1]);
  
      *n3 = *n1 + *n2;
  
      return n3;
  }
  
  my_class.point_to_func = save_the_func // point_to_func is the void* member
  </code></pre>
  
  <p>What do you have to do to finally get a void* pointing to the lambda function? Like I said, a non-lambda function works just fine.</p>
  
  <p>The reason I want it this way is because eventually I want my code to look like this:</p>
  
  <pre><code>std::vector&lt;function_entry&gt; MyFuncEntry ={
  add_function("MRP_DoublePointer2", "double", "double,double", "n1,n2", "add two numbers",
      [](void** arg, int arg_sz)-&gt;void* {
      double* n1 = In(arg[0]);
      double* n2 = In(arg[1]);
      double* n3 = In(arg[arg_sz-1]);
  
      *n3 = *n1 + *n2;
  
      return n3;
  }),
  
  add_function("MRP_DoublePointer3", "double", "double,double", "n1,n2", "add two numbers",
      [](void** arg, int arg_sz)-&gt;void* {
      double* n1 = In(arg[0]);
      double* n2 = In(arg[1]);
      double* n3 = In(arg[arg_sz-1]);
  
      *n3 = *n1 + *n2;
  
      return n3;
  })
  
  };
  </code></pre>
  
  <p>In other words, I want to define a function and some other needed parameters in the same place. Add_function returns a function_entry class that holds some strings plus the lambda function, basically I'm trying to define those strings next to the function so it's easier to maintain, it's not in two different places.</p>
  
  <p>If this is bad / computationally expensive then I guess I should stick with non-lambda. </p>
  
  <p>Here's the error I'm getting:
  <a href="https://i.stack.imgur.com/C0wuI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/C0wuI.png" alt="lambda error"></a></p>