Shame on me. I was wondering, why my Sprite data is corrupted after copying to vector class, which was causing Debug assertion failed – vector iterator is not dereferencableerror.
And that is why. Because I have not implemented copy constructor for Sprite class this code was created a problem:
m_alienShipList.push_back(AlienShip(position, speed, m_screeSize, m_alienShipTexture));
how it is working.
Because shallow copy has been made, I was deleting the memory I was trying to use after.
I had now it is true for Pointers, but not for Vectors. But seems vector is acting in similar manner to pointer.
My knowledge extended from
When use Pointer use Gang Of Three
When use Pointer OR Vector use Gang Of Three
Problem appears to be even deeper. I was storing vector<QuadSheet>::iterator inside each Sprite. Iterator is very similar to pointer. But problem is, every time I add new Object to vector, old Iterator became invalid. And so, I can’t rely on that, and of course, I just can’t allow it to be copied to another object.
Every day I see more necessary to create my own list class.