<bg***@yahoo.comwrote in message
news:11**********************@e65g2000hsc.googlegr oups.com...
Hi,
Lets say I have an class called Base which is inherited by a class
called Top. Now lets say I want to assign an object of type Base to an
object of type Top, how can I do this so that all the members present
in the Base object are assigned to the corresponding members in the
Top object, with the remaining values set to null?
You could implement a custom assignment op or conversion ctor that takes a
Base object and calls the base class' assignment op after upcasting the this
pointer to base, or calling it explicitely.
Of course you'd have to set the remaining member variables of Top to zero
manually but usually that would be taken care of by the initial constructor
anyway (if there is no reason to set some variables to a predefined state
that is not valid anymore after the assignment of a base object).
Cheers
Chris