From: Roedy Green on
On Wed, 17 Mar 2010 12:04:59 -0700 (PDT), Michael Preminger
<michaelprem123(a)gmail.com> wrote, quoted or indirectly quoted someone
who said :

>I have an application where I use different types of persons.
>Sometimes I need to convert a general Person (superclass) into a
>specific one(subclass)
>
>Is there a way to do it per constructor of the subclass, like:
>
>public Subperson (Person person)
> without explicitly copying the member values from the super object
>and destroying it later?

I have been complaining about this for a long time. A copy
constructor like that could be implemented so efficiently as a single
move bytes instruction. As it is, you have to write it out field by
field. The problem is maintenance. Every time you add a field, you
have to maintain your copy constructor.

It is a bug generator. There are so many tiny slips you could make.

What you could do is write a generator that looks at the base class
code and generates the code for a copy constructor. You run this any
time you modify the base class. This avoids buggy code, but still
takes longer than it need do.

The last time I brought it up, Sun said there was not enough interest
in it to implement an efficient syntax.
--
Roedy Green Canadian Mind Products
http://mindprod.com

Responsible Development is the style of development I aspire to now. It can be summarized by answering the question, �How would I develop if it were my money?� I�m amazed how many theoretical arguments evaporate when faced with this question.
~ Kent Beck (born: 1961 age: 49) , evangelist for extreme programming.