class B{
private:
int a;
}
class D: public B{
private:
int b;
}
B* b = new B;
Now for some reason I want turn b
into a D*
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 ?