Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>std::vector</code> is part of the STL, so any description of <code>std::vector</code> will do. The underlying implementation may differ slightly, but all conformant versions of STL must provide the same interface and the same guarantees for <code>std::vector</code>. I can't find in quickly on MSDN, but here are two such descriptions of <code>operator=</code>:</p> <ol> <li><a href="http://www.cplusplus.com/reference/stl/vector/operator=/" rel="nofollow noreferrer">http://www.cplusplus.com/reference/stl/vector/operator=/</a></li> <li><a href="http://www.sgi.com/tech/stl/Vector.html" rel="nofollow noreferrer">http://www.sgi.com/tech/stl/Vector.html</a></li> </ol> <p>Now, the second part of your question puzzles me. What would you expect <code>operator=</code> to do on a vector if not "copy everything from A into B"? </p> <p>In your example, your question was "how to make sure the old v get cleared?". I can interpret this in one of two ways: You might be asking "how do I know that this assignment <code>v = vector&lt;double&gt;(200,2)</code> will overwrite the contents of <code>v</code> and not append to it?". The answer is that you know that because that's the definition of how <code>operator=</code> works for STL containers. Any standards compliant implementation is guaranteed to work that way.</p> <p>You might also be asking "what happens to the contents of <code>v</code> when I overwrite them using the assignment <code>v = vector&lt;double&gt;(200,2)</code>?" The answer is that they are deallocated, and if they are objects, their destructors are called. Note the important distinction that if the vector contains <em>pointers to</em> objects, the pointers themselves are deallocated, but <em>not</em> what they point to.</p> <p>If I didn't answer your question, please try to clarify it.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload