Consider two classes, PersonClass and LawyerClass.
If LawyerClass derives from PersonClass, you can create a PersonClass* as a LawyerClass, like
PersonClass* Person = new LawyerClass;
then you can convert it to a LawyerClass* with
LawyerClass* Lawyer = static_cast<LawyerClass*>(Person);
However, if you don't know that the person should be a lawyer to start with:
PersonClass* Person = new PersonClass;
is there any hope of transforming him into a lawyer? This:
LawyerClass* Lawyer = static_cast<LawyerClass*>(Person);
does not work - Lawyer is invalid after the cast.
The reason I need to do this is that there is a library I am using that has a reader class, say ImageReader that returns an Image. Then I have created a subclass called FancyImage and I want to convert the output from the reader (Image) to my FancyImage but I cannot control what the reader outputs.
Any thoughts?
Thanks,
Dave