1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
bf(C++) offers two ways to (run-time) hi(type identification: run-time)
retrieve the type of objects and expressions. The possibilities of bf(C++)'s
run-time type identification are limited compared to languages like
hi(Java) bf(Java). Usually
i(static type checking) and i(static type identification) is used in
bf(C++). Static type checking is possibly safer and certainly more efficient
than run-time type identification and should therefore be preferred over
run-time type identification. But situations exist where run-time type
identification is appropriate. bf(C++) offers run-time type identification
through the emi(dynamic cast) and ti(typeid) operators.
itemization(
it() A tt(dynamic_cast) is used to convert a base
class hi(base class: converting to derived class) pointer or reference to a
derived class pointer or reference. This is also known as emi(down-casting).
it() The ti(typeid) operator returns the actual type of an expression.
hi(expression: actual type)
)
These operators can be used with objects of classes having at least one
virtual member function.
|