In C++, RTTI (Run-time type information) is a mechanism that exposes information about an object’s data type at runtime and is available only for the classes which have at least one virtual function. It allows the type of an object to be determined during program execution
For example, dynamic_cast uses RTTI and following program fails with error “cannot dynamic_cast `b’ (of type `class B*’) to type `class D*’ (source type is not polymorphic) ” because there is no virtual function in the base class B.
Adding a virtual function to the base class B makes it working.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Virtual Functions and Runtime Polymorphism in C++ | Set 1 (Introduction)
- Runtime Polymorphism in various types of Inheritance in C++
- Runtime and Compile-time constants in C++
- Data type of character constants in C and C++
- Can a C++ class have an object of self type?
- Type difference of character literals in C and C++
- Function overloading and return type
- Type of 'this' pointer in C++
- const_cast in C++ | Type Casting operators
- Type Inference in C++ (auto and decltype)
- Data Type Ranges and their macros in C++
- Conversion of Struct data type to Hex String and vice versa
- Array Type Manipulation in C++
- Bool data type in C++
- Comparison of boolean data type in C++ and Java
- C++ set for user define data type
- What is the size_t data type in C?
- Is there any need of "long" data type in C and C++?
- C++ map having key as a user define data type
- reinterpret_cast in C++ | Type Casting operators