Copying parent class object into new subclass object
Joined: Jan 30, 2003
Suppose I have a class (Dog), a subclass (Poodle), and a Dog object that I want to use to create a Poodle object.
One way to do that would be something like this:
Having to explicitly list all of the fields of the Dog object to set them in the Poodle object feels wrong. Is there a better way to do this?
Joined: Oct 13, 2005
That shouldn't work if all the fields are correctly labelled private. If there is going to be that sort of copy constructor, it ought to be in the Dog classYou can have other constructors if you wish. You would have to check the design: do you really want a Poodle identical to another Dog in all respects except curliness?