I am trying to abstract sections of code to be platform independent.
I have one section of code that is creating objects of Base class IModel
.
std::shared_ptr<IModel> joint_model_3d = std::make_shared<IModel>();
I have another section of code that is responsible for rendering. In order to render the object I need to convert it to the derived class Direct3DModel
class Direct3DModel : public IModel
I know that I can do a dynamic_cast
from Direct3DModel
to IModel
for sections of code that are platform independent, and then dynamic_cast
back into Direct3DModel
for rendering.
My question is, can I create an object of the Base class IModel
in the platform independent code, which is not supposed to know Direct3DModel
, and convert it to Direct3DModel
when I need it for rendering.
Would I need some kind of object creator class that is not platform independent for this?
question from:
https://stackoverflow.com/questions/65852204/convert-from-a-base-object-to-a-derived-object-in-c 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…