Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As already mentioned in the comments and by others, the problem occurs because you did not follow the <a href="http://en.wikipedia.org/wiki/Rule_of_three_%28C%2B%2B_programming%29" rel="nofollow">rule of three</a>, that is, since you had to define a custom destructor(to delete the dynamically allocated memory), you should at least define a custom copy constructor(which does a deep copy of the array, that is, it allocates new memory and copies the content of the old array) and a custom copy assignment operator(that does essentially the same, so you could implement one in terms of the other).</p> <p>Example code for a copy constructor(suboptimal, of course):</p> <pre><code>test(const test &amp;other) { a=other.a b=new Uint8[a]; for(size_t i=0;i&lt;a;++i) b[i]=other.b[i]; } </code></pre> <p>As can be seen, this would involve a little work and is quite tedious, which is why you should prefarably follow the <a href="http://flamingdangerzone.com/cxx11/2012/08/15/rule-of-zero.html" rel="nofollow">rule of zero</a> and use classes that already deal with ownership issues intrinsically(which in your case should propably be a std::vector), so instead of dealing with your dynamically allocated array directly, change it to something akin to this:</p> <pre><code>class test { public: std::vector&lt;Uint8&gt; b; test(int size) { b.resize(size); } } </code></pre> <p>And all your problems vanish, because std::vector deals with the required deep copy itself, without your class having to worry about it.</p> <p>I hope this helps ;-)</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.
    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