Note that there are some explanatory texts on larger screens.

plurals
  1. POc++ vector problems
    primarykey
    data
    text
    <p>I am working with a <code>std::vector</code> to hold some objects that have dynamically allocated members, and when I go to put the Things into the vector a few things happen that I am not understanding.</p> <ol> <li><p>I call <code>push_back()</code> and use the constructor of the objects as the argument, but for some reason it goes to the destructor of the object. why is this; it should be adding not deleting?</p></li> <li><p>I call <code>push_back()</code> a second time doing the same as before, but this time it throws an illegal memory access at <code>dbgdel.cpp</code> operator delete (line 52). but delete should never be called in a constructor, or <code>push_back()</code>.</p></li> </ol> <p>I am uncertain what sections of code are pertinent to this question as the lines in question are pretty entrenched in a method. </p> <p>Edit: Code added</p> <pre><code>class Thing{ int** Array; int size; // of square array Point current; // location Thing(int _n){ // allocates, and gives values to the array, and members // only constructor } }; class ThingMgr{ Thing * Control; Thing * Current; Thing * Previous; int size; // size of all. same use as in Thing ThingMgr(int _n){ size = _n; Control = new Thing(size); Current = new Thing(size); Previous = new Thing(size); } void rearrange(int _num){ std::vector&lt;Thing&gt; possibles; // performs deterministic work on members // [0] first possibles.push_back(Thing(size)); // this succeeds // [1] second possibles.push_back(Thing(size)); // this fails // more operations to be performed never reached. } }; </code></pre>
    singulars
    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.
 

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