Re: can I turn base object into inherited one?
On Apr 14, 2:15 am, Ian Collins <ian-n...@hotmail.com> wrote:
alexl wrote:
I have 2 classes,
class base {
public:
some virtual functions
}
class derived : public base {
public:
derived(base* b);
}
is there a simpler way to turn a base object into derived
than the following
base* b = new base();
b->do some stuff
now he becomes derived
base* d = new derived(b);
No, a Base is a Base. You can't morph it into something else.
You can simulate this sort of behavior, however, with a
variation of the letter envelop idiom. Typically, of course,
this idiom is only used to give polymorphic behavior to an
object with value semantics, but since value semantics include
assignment, with the target object acquiring the dynamic type of
the assigned object, the potential is there.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34