Cast object from derivative to base and vice versa

If I drop the object into a base type and save it on std :: map, and then return it and convert it to a derived type, do I still have the correct data in the members of the derived class?

Do I need to make any specific appearance?

+6
source share
1 answer

If you overlay pointers to an object, this is not a problem, because pointers will point to the same object.

If you execute the actual object, all information from this subclass will be lost when it is converted to a superclass, so dropping it back will not restore this information.

+12
source

Source: https://habr.com/ru/post/908334/


All Articles