The cast of problem child10/16/2023 ![]() If a field that is defined on the child class is used on a base object cast as the child object, the program will reference memory that is not part of the instance. That's why casting an instance of a base object to a child object results in undefined behavior the runtime interprets the base object as a child object and uses the pointer for the object as a starting point for referencing data of the object. ![]() When an object is cast, the only thing that changes is how the program sees and works with the object. If you are confused about how casting works:Īn object never actually changes during a cast - in truth an object is really just a contiguous block of memory. should not) cast an instance of a base class into a child class. You can cast an instance of a child class to a base class, but you cannot (well.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |