string vector not getting properly assigned using set_union
<p>I think I'm lacking some basic understanding of assignment in C/C++ here!  I have a function that computes the set union between two string vectors.  The reason I do this is because the algorithm library's function <code>set_union</code> requires that both vectors are sorted first and if I do it the following way then I can't forget to sort:</p>

<pre><code>vector&lt;string&gt; SetOperations::my_set_union(vector&lt;string&gt; set1,
                                            vector&lt;string&gt; set2) {
    sort(set1.begin(), set1.end());
    sort(set2.begin(), set2.end());

    vector&lt;string&gt; v;
    set_union(set1.begin(), set1.end(), set2.begin(), set2.end(), back_inserter(v));
    return v;
}
</code></pre>

<p>I then do the following:</p>

<pre><code>vector&lt;string&gt; vec = set_ops.my_set_union(vec1, vec2);
</code></pre>

<p>where <code>vec1</code> and <code>vec2</code> are string vectors containing a single <code>"a"</code> and <code>"a"</code> each and <code>set_ops</code> is an instantiation of a class that I have these set operations in (like the one above).  They both definitely have these elements - I have printed the two vectors out.</p>

<p>For some (simple?) reason, <code>vec</code> ends up having a single element of <code>"a"</code> instead of two elements (<code>"a"</code> and <code>"a"</code>).  </p>

<p>Any ideas what I'm doing wrong?  Am I meant to a copy function or something?</p>

<p>Thank you :).</p>
