title: Casting int to void pointer
body: <p>Good day,
  I just started to learn void pointers in c++ and now I'm writing binary tree where value stored in each node is void pointer to a value.</p>
  
  <pre><code>struct TreeNode
  {
      int count;
      void* data;
      TreeNode *left;
      TreeNode *right;
      };
  </code></pre>
  
  <p>The problem occurred in very first method-add method.
  my method now takes int a a parameter and return nothing
  At the very beginning i create new node.
  To do that I need to cast integer into void.
  Program compiles and first element adds to root correctly-however then when i send another number to method it stores in root again.
  so if in main i have something like
  tree.addToTree(12);
  tree.addToTree(13);
  than it would store 12 first and than right after else statement(code below)how that root->data i 13.</p>
  
  <pre><code>void Tree::addToTree(int num)
  {
      if(root==NULL){
          root= new TreeNode();
          root-&gt;data=&amp;num;
          //((int *)(root-&gt;data)) = num;//i tried to convert to void* in this way but it give me segmentation fault
          root-&gt;left=NULL;
          root-&gt;right=NULL;
      }
      else{
          //here root value is already changed
          int *intPtr = static_cast&lt;int*&gt;(root-&gt;data);
          cout &lt;&lt; "key2" &lt;&lt; *intPtrT &lt;&lt; endl;
          //TreeNode* current= insert(num,root);
      }
  }
  </code></pre>
  
  <p>as i understood thats because i use &amp;num so my parameter always tore in one place and a root is "connected" to &amp;num it change as well.</p>
  
  <p>I tried to find solution but was unsuccessful.
  Is there a way to cat int to void pointer?</p>