title: passing a vector between functions via pointers
body: <p>It was suggested to me to use pointers to add a vector that I wanted to pass from some existing function to another function. I am really stuck on how to get the information back <em>out</em> of that pointer though. I've tried a number of things I've read here and there so let me demonstrate what I'm talking about.</p>
  
  <p>primary program:</p>
  
  <pre><code>std::vector&lt;float&gt; * dvertex=NULL;
  
  track.calculate(irrelevant stuff, dvertex)
  </code></pre>
  
  <p>secondary program (track, calculate)</p>
  
  <pre><code>track::caclulate(irrelevant stuff, vector&lt;float&gt; * dvertex)
  {
  ...
  vector&lt;float&gt; pos;
  ... pos filled after some calculations
  if(! (dvertex==NULL))
  {
    dvertex = &amp;pos1;
  }
  </code></pre>
  
  <p>back to primary, unless I messed up something above, here's some things I've tried</p>
  
  <p>1</p>
  
  <pre><code>(*dvertex).at(0)
  float z = (*dvertex).at(0)
  </code></pre>
  
  <p>2</p>
  
  <pre><code>(*dvertex)[0]
  </code></pre>
  
  <p>and a bunch of stuff that just plain didn't compile. I'm quite stuck as I'm not sure how to get the specific values out of that vector in the main program. I even thought it might be the if(! (dvertex==NULL)) bit, so I changed it to if(dvertex==NULL) but still no joy. Any help would be greatly appreciated.</p>
  
  <p>*<strong>Edit/Update</strong>*Thanks so much everyone for the help, but I fear I'm still doing it wrong.</p>
  
  <p>So following the suggestions that I just pass a reference: I did this:</p>
  
  <p>primary</p>
  
  <pre><code>std::vector&lt;float&gt; dvertex;
  track.calculate( foo, &amp;dvertex);
  </code></pre>
  
  <p>secondary stayed the same (with !Null check)</p>
  
  <p>primary</p>
  
  <pre><code>std::cout&lt;&lt;dvertex[0]&lt;&lt;std:endl; 
  </code></pre>
  
  <p>(among other attempts to actually use the data)</p>
  
  <p>Thanks a lot for any thoughts on what I'm still doing improperly. Everything compiles, the program just freezes when it gets to a point that the data from dvertex is used.</p>
  
  <p><strong>Edit:Final fix</strong></p>
  
  <p>in the secondary program I needed</p>
  
  <pre><code>*dvertex = pos1;
  </code></pre>
  
  <p>instead of</p>
  
  <pre><code>dvertex = &amp;pos1;
  </code></pre>