#754 – Downcast to a Reference to a Derived Class

If you have a variable that is a reference to a parent class, but it actually refers to an instance of a derived class, you can use a downcast operation to assign the reference to a variable whose type matches the derived class.

For example, assume that you have a Dog class and a Terrier class, which inherits from Dog. You might have a reference to a Dog that actually refers to an instance of a Terrier. To get at methods that are unique to Terrier, you’d downcast the Dog reference to a Terrier reference.