Avatar of LuckyLucks
LuckyLucks

asked on 

assigning a child class its parent

Hi

I have a class hierarchy as follows:
A (parent)->B(child)


I create an object A. A a=new A();

Somewhere, later in the code, I want to create an object B, called b, and want to specifically assign the object a as its parent. Is there a way to do this in C++?

Normally, I would do something like this:
B b=new B();

B's constructor would make a call to A's constructor
B::B()
:A(){
}

But if i have a parent object already instantiated, is there a way to assign that particular object as a child object's parent at the time the child is instantiated?

thanks
C++

Avatar of undefined
Last Comment
sarabande

8/22/2022 - Mon