Please, answer the with c++ Module 9: Odds and Ends Questions Question 1 How is
ID: 3868692 • Letter: P
Question
Please, answer the with c++
Explanation / Answer
1)Answer:
static_cast operator:
The static_cast operator converts a given expression to a specified type.
static_cast can perform conversions between pointers to related classes, not only upcasts (from pointer-to-derived to pointer-to-base), but also downcasts (from pointer-to-base to pointer-to-derived). No checks are performed during runtime to guarantee that the object being converted is in fact a full object of the destination type. Therefore, it is up to the programmer to ensure that the conversion is safe. On the other side, it does not incur the overhead of the type-safety checks of dynamic_cast.
Syntax:
The output of this example is:
dynamic_cast operator:
The dynamic_cast operator checks the following types of conversions at run time:
dynamic_cast can only be used with pointers and references to classes (or with void*). Its purpose is to ensure that the result of the type conversion points to a valid complete object of the destination pointer type.
This naturally includes pointer upcast (converting from pointer-to-derived to pointer-to-base), in the same way as allowed as an implicit conversion.
But dynamic_cast can also downcast (convert from pointer-to-base to pointer-to-derived) polymorphic classes (those with virtual members) if -and only if- the pointed object is a valid complete object of the target type.
example: