passing a vector of pointers and erasing duplicates
<p>I am trying to erase a vector of pointers that I pass by value into some function. The reason why I pass by value is that I plan to erase these values in numerous calls to the function. So if I pass by pointer/reference I could not achieve this.</p>

<p>First of all is the statement above correct?</p>

<p>Here is some example code:</p>

<pre><code>vector&lt;Boson*&gt;* BosonMaker::remove_duplicates(vector&lt;Boson*&gt;* boson_candidates, vector&lt;Particle*&gt; child_candidates){
  vector&lt;Particle*&gt; used_leptons.clear();

  // This needs deleting at some point
  m_unduplicated_bosons = new vector&lt;Boson*&gt;();

  for(int i_b = 0; boson_candidates-&gt;size(); i_b++){

    vector&lt;Particle*&gt;::iterator child1_finder = find(used_leptons.begin(), used_leptons.end(), boson_candidates-&gt;at(i_b)-&gt;Child1());

    //Search pointer will reach end of collection if child isn't in the used_leptons vector
    if (child1_finder == used_leptons.end()) {
      vector&lt;Particle*&gt;::iterator child2_finder = find(used_leptons.begin(), used_leptons.end(), boson_candidates-&gt;at(i_b)-&gt;Child2());

      if (child2_finder == used_leptons.end()) {
        used_leptons.push_back(boson_candidates-&gt;at(i_b)-&gt;Child1());
        used_leptons.push_back(boson_candidates-&gt;at(i_b)-&gt;Child2());
        // And add the boson to the vector of final bosons
        unduplicated_bosons-&gt;push_back(boson_candidates-&gt;at(i_b));
      }
    }

  }
  // Now make a vector of unused leptons
  for (int i_l = 0; i_l &lt; used_leptons.size(); i_l++) {
       vector&lt;Particle*&gt;::iterator lepton_finder = find(child_candidates.begin(), child_candidates.end(), used_leptons.at(i_l));
       child_candidates.erase(lepton_finder);  
  }

  return unduplicated_bosons;
}
</code></pre>

<p>I would then use this member function inside the class like so</p>

<pre><code>vector&lt;Boson*&gt; *m_boson_finals_elpair = remove_duplicates(&amp;m_boson_electronPair_candidates, m_all_particle_candidates);
vector&lt;Boson*&gt; *m_boson_finals_mupair = remove_duplicates(&amp;m_boson_muonPair_candidates, m_all_particle_candidates);

vector&lt;Boson*&gt; *m_boson_finals_elneutrino = remove_duplicates(&amp;m_boson_electronNeutrino_candidates, m_all_particle_candidates);
vector&lt;Boson*&gt; *m_boson_finals_muneutrino = remove_duplicates(&amp;m_boson_muonNeutrino_candidates, m_all_particle_candidates);
</code></pre>

<p>My question is:</p>

<p>Would m_all_particle_candidates which is</p>

<pre><code>vector&lt;Particle*&gt;  m_all_particle_candidates;
</code></pre>

<p>be different in each call of remove_duplicates?</p>

<p>I think I am trying to ask is the iterator lepton_finder erased from the vector and not the actual object Particle since I have passed by value?</p>

<p><strong>Note: There was a typo in the remove_duplicate funtion. I passed by pointer and not value. it should be value</strong></p>
