Tutorial by Examples

You can retrieve the implementation defined name of a type in runtime by using the .name() member function of the std::type_info object returned by typeid. #include <iostream> #include <typeinfo> int main() { int speed = 110; std::cout << typeid(speed).name() <...
Use dynamic_cast<>() as a function, which helps you to cast down through an inheritance hierarchy (main description). If you must do some non-polymorphic work on some derived classes B and C, but received the base class A, then write like this: class A { public: virtual ~A(){} }; class B...
The typeid keyword is a unary operator that yields run-time type information about its operand if the operand's type is a polymorphic class type. It returns an lvalue of type const std::type_info. Top-level cv-qualification are ignored. struct Base { virtual ~Base() = default; }; struct Deri...
Use dynamic_cast for converting pointers/references within an inheritance hierarchy. Use static_cast for ordinary type conversions. Use reinterpret_cast for low-level reinterpreting of bit patterns. Use with extreme caution. Use const_cast for casting away const/volatile. Avoid this unless you ar...

Page 1 of 1