4 Dynamic casting

Dynamic casting is performed at compile time. It checks the actual type of an object before deciding whether a cast operation makes sense or not. The syntax is the same as static cast, but the operation is different.

If a dynamic cast is deemed invalid, the cast operator returns a NULL pointer. This is how we can check if the cast operation is successful or not. However, dynamic cast can only applied to polymorphic types. A polymorphic type is one that has at least one virtual method.



Subsections

Copyright © 2006-10-12 by Tak Auyeung