upcast at runtime. (Morph from Base Class to derive Class)

Djburn

New Member
\[code\]class B{ private: int a;}class D: public B{ private: int b;}B* b = new B;\[/code\]Now for some reason I want turn \[code\]b\[/code\] into a \[code\]D*\[/code\] Type of Object.e.g. retain the information of B and become D with extra Informations required.What I am currently thinking of is. static_cast to do the upcasting. the additional attributes will be set to null or garbage. then assign the additional attributes manually. But this leads to a dangling pointer risk. If the copy constructor is not coded with enough care.So what else could be the proper Solution ?
and is there any solution of the Puzzle if we think it from a PHP perspective ?
 
Back
Top