Binding in C++

C++ is also a strange mix of both static and dynamic behaviors. Instances of classes are not polymorphic -- if you declare a variable of type Mammal then it will always hold a Mammal value, however pointers and references are polymorphic -- if you have a pointer to a Mammal it could easily be pointing to a Cat.

Until recently, values did not have any type information. This has changed somewhat since the introduction of the RTTI system. Now some values, namely values that are derived from classes that have at least one virtual function, will retain some knowledge of their actual type.

Depending upon how one uses the virtual keyword and the type of object used for the receiver, method binding can optionally be performed using either the static or dynamic type of the receiver.

As with Object Pascal, the legality of a message is always checked using the static type.

Until recently there were no facilities for the testing of reverse polymorphism. With the introduction of the RTTI, this has changed slightly, and now at least some values know their own type.

As with C before it, a change in type, including the change in type necessitated by reverse polymorphism, is performed using a cast operator. However, the validity of this change is not checked at run time.

[audio] [real] Text to accompany slide17, in Chapter 10 of An Introduction to Object-Oriented Programming