title: Recasting *void function arguments
body: <p>I posted a question <a href="https://stackoverflow.com/questions/8434884/nlopt-with-armadillo-data">here</a> earlier that I think I can answer if someone can help me with the following: </p>
  
  <p>I have a function</p>
  
  <pre><code>double func(void* data)
  </code></pre>
  
  <p>I want to pass in an object or struct. (In my case an armadillo matrix or even just and std::vector).</p>
  
  <p><em>How do I pass a pointer to an object as an argument to func() and then, once inside func(), how do I recast the void pointer into its original type?</em></p>
  
  <p><strong>Edit</strong>: Here's what ended up working, where mat is the Armadillo matrix class:</p>
  
  <pre><code>mat A(2,2);
  A &lt;&lt; 1 &lt;&lt; 2 &lt;&lt; endr &lt;&lt; 3 &lt;&lt; 4; // A=[1,2; 3,4]
  func(&amp;A);
  </code></pre>
  
  <p>and in func:</p>
  
  <pre><code>double func(void* data) {
     mat* pB = (mat*)(data);
     mat B = pB[0];
  }
  </code></pre>
  
  <p>The matrix B and A now contain the same data.</p>