I can't see the constructor for the PolygonNode
class. Is the link_
pointer initialized to null on creation? If not, that may be the problem manifesting itself in the error you get. You have to make sure, the link_
pointers in the PolygonNode
instances get initialized to null. Define appropriate constructors.
Do you have a copy constructor defined for your polygon class? I can't see one in the code posted, but maybe you just didn't paste it and you have one. If not, that is one of possible sources of serious problems.
The copy constructor, that gets synthesized automatically by the compiler will just copy the pointers in the Polygon
class.
Your assignment operator takes the argument by value
Polygon& operator= (Polygon ply);
This makes use of the copy constructor. If it's the automatically synthesized one, ply
inside the operator has pointers pointing to the same list, the argument passed by value to the operator owns. ply
behaves like it owned the list too and the list gets destroyed when ply
goes out of scope. The original argument is left with dangling pointers.
You should define correct copy constructor.
You should also consider taking the argument in the assignment operator by const reference. I don't see a reason to take it by value. Maybe you have one, but even if you do, you can change it temporarily, to test the operator, before you define correct copy constructor. In your operator you should check for self-assignment. All I can see now is adding new nodes to the old Polygon
. I don't think it's right, but I guess it's just for testing now.