I want to make a new object where the constructor of a derived class will accept the base class as its parameter and use it as a template assigning all the variables of the base class to the newly constructed derived class. I need an actual object as down-casting will only provide undefined behavior. I hope there is a simple way to do this.
One problem I ran into was that things like the copy constructor are all private and in the generated body. I wanted to use the template variable in the New Object function however it only works if it is the same class type.
To add context to what I’m doing, I’m trying to deserialize a large hierarchy from json. Due to it’s size, the derived classes shouldn’t have to re-implement the deserialization code but rather have the base class do it and pass itself down as the base object then the derived will use its variables to create itself and so on. The problem just lies in using the base class without casting.