// A program that constructs LineSegments, copies them, and assignmens them. // Problems occur when the LineSegment objects are destructed. #include #include "point-lineseg.h" using namespace std; void h(){ LineSegment ls1, // LineSegment(10) constructed ls2 = ls1, // copy initialization ls3; // LineSegment(10) constructed ls3 = ls2; // copy assignment - ls3 is now a copy of ls2. // Here all LineSegments ls1, ls2 and ls3 refer to the same Point array // because the Point pointers are just copied in the // initialization and the assignment shown above. // Destructors called for ls1, ls2, ls3 on exit from h. // Trouble for the two last destructions. We delete the linesegment on the free store more than once! } int main(){ h(); }