Comp 272 Program 6 Dordal April 17, 2001 Due: May 4, 2001 (May 4 is the date of the final; programs will be accepted through May 7.) You are to create a copy ctor, a dtor, and an assignment operator for the shape Group class. Do *not* do the equality operator that was mentioned in a previous version. The dtor should properly deallocate all the space used. The copy ctor and operator= should allow the following (assuming group g1 has been created): Group g2 = g1; // initialization Group g3; g3 = g1; // true assignment g1.move(x,y); and now g2 and g3 should *not* have moved. For the dtor, you simply need to call delete on every pointer in _shapelist; this will automatically call the Group dtor (~Group) on each subgroup. When delete is called on a pointer, the dtor of the pointed-to object is invoked on the thing pointed to; see "Destruction and Deletion" on page 365 of Horstmann. Because of this principle, if you have a tree of Groups and subGroups then the subGroups will be deallocated recursively. In effect you will presume that pointers are never shared. This you can enforce with operator= (by making sure that the new copy of the Group doesn't share pointers with the old), but cases such as the following can get you in trouble: Group g1, g2; Shape * p = new Rectangle (....); g1.add(p); g2.add(p); // now g1 and g2 share p! You can fix this with clone(), by making the second g2.add(p->clone()). What could happen if you don't do this? For the equality operator, you can do one of two things. THe first is to define a virtual operator== function on shapes generally, in which case Group::operator== just checks that all the subshapes have the same typeid and, if so, compares them. Or you can just define operator== for Groups, and rely on the built-in version for any non-Group shape objects. You will still use typeid on each pair of corresponding items in _shapelist, but you will also check the typeid value to see if it is typeid(Group), in which case you will invoke the Group version.