To make what
norm b said a little more clear, in the following code:
34 35 36 37 38 39 40
|
//clear old vector and copy it.
this->vectorInt.clear();
this->vectorInt.reserve(other.vectorInt.capacity());
for(std::size_t i = 0; i != other.vectorInt.capacity(); i++){
this->vectorInt[i] = other.vectorInt[i];
}
|
On line 35, you invoke the
clear method of
vectorInt.
clear sets the size of the vector to 0. As has already been noted, the capacity and size of the vector are different things, so when you set the capacity on line 36, you do
not affect the size of the vector at all.
When you reach line 39,
vectorInt has no elements. In other words, there is no valid index which may be used with
vectorInt. Use
resize on line 36 (and resize to the size of
other.vectorInt, not the capacity.) The use of capacity on line 38 has already been addressed. The
clear on line 35 is unnecessary since you're going to overwrite those elements anyway.
By the way, whatever your
arrayIntPtr is intended to do, it's not doing it. You don't treat it consistently and it is entirely unsafe to use most of the time, given the constructors you've supplied (and two consecutive uses of operator= on the same object will result in a memory leak.)