简体   繁体   中英

Cast object from derived to base and than back

If i cast an object to the base type and store it in a std::map, and then get it back and recast it to the derived type, do i still have the correct data in the derived class members ?

Do i need to make a specific kind of cast ?

If you're casting pointers to the object, it's no problem because the pointers will still point to the same object.

If you're casting the actual object, all information from the subclass will be lost when its converted to the superclass, so casting it back won't restore that information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM