Re: copy constructor

[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]

Posted by David Longley on April 22, 2001 at 02:40:08:

In Reply to: copy constructor posted by Eric on April 21, 2001 at 16:25:20:

Create a function that returns a pointer to a creature * (or animal */plant * if you have 2 lists, etc) and make it pure virtual in your creature class. Then write implementation for each of your derived classes that will create a new creature of the derived type. Call that function within your ecosystem copy constructor and append the returned pointer to your new list.

: Do we need to implement a copy constructor for our ecosystem?
: I assume the list has a copy constructor defined, so implementing an ecosystem copy constructor would only be used to make a new ecosystem have its own copies of each creature and plant.
: However, I don't see how we can make copies of the creatures in the list without knowing which type of creature each pointer is to call its constructor.
: So do we need to have copy and operator= that go that deep, and if so how do we copy the values of the list pointers without storing type information(which the specs say we can't do)?

Follow Ups:

Post a Followup




Optional Link URL:
Link Title:
Optional Image URL:

[ Follow Ups ] [ Post Followup ] [ CS2704 Web Discussion Board ] [ FAQ ]