| Author |
Copying parent class object into new subclass object
|
Wally Hartshorn
Ranch Hand
Joined: Jan 30, 2003
Posts: 77
|
|
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?
|
Wally Hartshorn
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
|
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?
|
 |
 |
|
|
subject: Copying parent class object into new subclass object
|
|
|