When is it safe to add object values to vectors on the heap?
<p>Let's say I have a structure named vertex with a method that adds two vertices:</p>

<pre><code>struct vertex {
    float x, y, z;

    // constructs the vertex with initial values
    vertex(float ix, float iy, float iz);

    // returns the value c = this + b
    vertex operator+(vertex b);
};

vertex::vertex(float ix, float iy, float iz){
    this-&gt;x = ix; this-&gt;y = iy; this-&gt;z = iz;
}

vertex vertex::operator+(vertex b){
    vertex c;
    c.x = this-&gt;x + b.x;
    c.y = this-&gt;y + b.y;
    c.z = this-&gt;z + b.z;
    return c;
}
</code></pre>

<p>In another calling function I want to add two vertices together and add the result to a <code>vector&lt;vertex*&gt;</code>. When is it safe to use the returned value to add to the given vector? If never, how would I implement it?</p>

<p>For example,</p>

<pre><code>vector&lt;vertex*&gt; v;
vertex a(1, 2, 3);
vertex b(4, 5, 6);
v.push_back(&amp;(a + b));
</code></pre>
