I think the problem in your Polygon class is that you have a vertices data element, which is apparently a raw pointer to Vertex used to store the raw array allocated with new[] :
vertices = new Vertex [aPolyToCopy.count];
You may also need to overload operator= (and the destructor), not just the copy constructor (see Rule of Three ); You did not specify all the code for your Polygon class, so it is unclear whether you have determined the correct assignment and destruction of the copy.
Note that you will simplify your code if you use a robust RAII container container like std::vector . Just add the data element " std::vector<Vertex> vertices; " instead of the data element " Vertex* vertices ", and std::vector will take care of copying, cleaning, etc. You do not need to do anything: all of this is automatically controlled by std::vector .
In general, in C ++, try to assemble classes that bring together convenient RAII structural blocks, such as std::vector and other direct resource managers.
source share