Chapter 13 - Worked Exercises 1
Exercise 1
Part 0 - Static Cast
What checks are imposed by the
static_castoperator?Is it at compile time or at runtime that these checks are performed?
Will
static_castalways return a value?There are two scenarios where
static_castshould be used, one related to inheritance, the other related to implicit type conversions. Describe these scenarios.What is upcasting and downcasting?
When should you not downcast an object pointer?
Part 1 - Dynamic Cast
How does
dynamic_castdiffer to that ofstatic_cast?What is the result of invoking
dynamic_cast?What is runtime type identification? Show a basic example illustrating this concept.
Why should you always check for the return value of a
dynamic_castoperation?
Part 2 - Reinterpret Cast
What is the effect on the underlying value of a variable when performing a
reinterpret_castoperation? How does it differ to that of implicit casting?
Part 3 - Const Cast
What is the purpose of const casting? Show a simple example of its usage.
Why should const cast only be used as a last resort? What alternatives should be explored before attempting to use a const cast?
Part 4 - Workshop
Please complete the Workshop section for Chapter 14 in the textbook (pg. 389).
Last updated
Was this helpful?