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.
- Runtime Polymorphism in various types of Inheritance in C++
- Virtual Functions and Runtime Polymorphism in C++ | Set 1 (Introduction)
- Type of 'this' pointer in C++
- Type Conversion in C++
- What is the size_t data type in C?
- Bool data type in C++
- Is there any need of "long" data type in C and C++?
- Array Type Manipulation in C++
- Can a C++ class have an object of self type?
- C++ map having key as a user define data type
- reinterpret_cast in C++ | Type Casting operators
- C++ set for user define data type
- static_cast in C++ | Type Casting operators
- C++ program to find the type of the given iterator
- Data type of character constants in C and C++
- Type difference of character literals in C and C++
- Function overloading and return type
- Catch block and type conversion in C++
- Data Type Ranges and their macros in C++
- Type Inference in C++ (auto and decltype)