Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Wrote this template move-enabled class for you.</strong> Study it and you'll get it.</p> <pre><code>/// &lt;summary&gt;Container.&lt;/summary&gt; class Container { private: // Here be data! std::vector&lt;unsigned char&gt; _Bytes; public: /// &lt;summary&gt;Default constructor.&lt;/summary&gt; Container(){ } /// &lt;summary&gt;Copy constructor.&lt;/summary&gt; Container(const Container&amp; Copy){ *this = Copy; } /// &lt;summary&gt;Copy assignment&lt;/summary&gt; Container&amp; operator = (const Container&amp; Copy){ // Avoid self assignment if(&amp;Copy == this){ return *this; } // Get copying _Bytes = Copy._Bytes; // Copies _Bytes return *this; } /// &lt;summary&gt;Move constructor&lt;/summary&gt; Container(Container&amp;&amp; Move){ // You must do this to pass to move assignment *this = std::move(Move); // &lt;- Important } /// &lt;summary&gt;Move assignment&lt;/summary&gt; Container&amp; operator = (Container&amp;&amp; Move){ // Avoid self assignment if(&amp;Move == this){ return *this; } // Get moving std::swap(_Bytes, Move._Bytes); // Moves _Bytes return *this; } }; // class Container </code></pre> <p>I'm always against of using value arguments like this:</p> <pre><code>function(std:vector&lt;item2&gt; items) </code></pre> <p>I always use either:</p> <pre><code>function(const std:vector&lt;item2&gt;&amp; items) function(std:vector&lt;item2&gt;&amp; items) function(std:vector&lt;item2&gt;&amp;&amp; items) </code></pre> <p>especially for larger data containers, and seldom:</p> <pre><code>function(std:vector&lt;item2&gt; items) </code></pre> <p>for smaller data, never vectors.</p> <p>This way, you're in control of what happens and that's why we do C++, to control everything.</p> <ul> <li>If you need a writable copy, just copy the const reference yourself in a variable.</li> <li>If you need it read-only, const reference prevents a new copy.</li> <li>If you want to edit original, just use reference.</li> <li>And use value arguments for small data when you feel lazy.</li> </ul> <p>Obviously, it all depends on what you're doing.</p> <p><em>I'm a self taught C++ developer. Far from an expert, especially in the C++ slang... but learning :)</em></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. 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