title: Accessing Vector of Nodes
body: <p>Just a quick C++ question. I've been trying to save a node inside a vector to the right child of a node.</p>
  
  <p>For example,</p>
  
  <p>I have a struct called node that has a pointer leading to a left child and a right child. 
  So: </p>
  
  <pre><code>struct node{
       node *left;
       node *right;
  };
  </code></pre>
  
  <p>My vector of nodes, </p>
  
  <pre><code>vector&lt;node&gt; nodeVec;
  </code></pre>
  
  <p>consists of nodes as well. </p>
  
  <p>The goal is to then take a node out of my vector and save as the right and left child of a new node.</p>
  
  <p>So:</p>
  
  <pre><code>node *tree = new node();
  tree-&gt;left = *nodeVec.at(0);
  tree-&gt;right = *nodeVec.at(1);
  </code></pre>
  
  <p>But it throws an error saying that it doesn't recognize the '*' operator. Trying just </p>
  
  <pre><code>tree-&gt;left = nodeVec.at(0)
  </code></pre>
  
  <p>It says that I can't convert a node to a node*.</p>
  
  <p>But if I use,</p>
  
  <pre><code>tree-&gt;left = &amp;nodeVec.at(0)
  </code></pre>
  
  <p>It succesfully saves the address inside my left child.
  I took a look at a couple of sites and answers and I think the one found here,</p>
  
  <p><a href="https://stackoverflow.com/questions/1910712/c-dereference-vector-pointer-to-access-element">Dereference vector pointer to access element</a>,</p>
  
  <p>might've been the most relevant. I gave it a shot and threw so many errors, I didn't quite understand.</p>
  
  <p>In short, from what i've read, I need to dereference the node inside my vector. But if it doesn't accept the '*' operator, how would one do that? </p>
  
  <p>Thanks in advance!</p>