I manipulate the vectors of objects defined as follows:
class Hyp{ public: int x; int y; double wFactor; double hFactor; char shapeNum; double* visibleShape; int xmin, xmax, ymin, ymax; Hyp(int xx, int yy, double ww, double hh, char s): x(xx), y(yy), wFactor(ww), hFactor(hh), shapeNum(s) {visibleShape=0;shapeNum=-1;};
When I create a Hyp object, allocate / write memory to visibleShape and add the object to the vector with the vector :: push_back, everything works as expected: the data pointed to by visibleShape is copied using the copy constructor.
But when I use vector :: erase to remove Hyp from the vector, the other elements move correctly. EXCLUDE visibleShape pointer elements that now point to invalid addresses! How to avoid this problem? Did I miss something?
c ++ pointers vector stl erase
matt Apr 20 2018-10-18T00: 00Z
source share