Sunday, January 22, 2006

casting from base classes

After visiting Schwetzingen I designed the following C++ question for today:

C++ has two reasonable options to cast from a base class to a sub class. These options are the static_cast operator and the dynamic_cast operator. Explain the differences between these two operators and compare their advantages and disadvantages.

Explain why one cannot use the dynamic_cast operator to cast from a base class that does not have a virtual function.

Explain why one cannot use the static_cast operator to cast from a virtual base class.

No comments: