cppforever.com

typeid

typeid — Runtime Type Information (RTTI)

The typeid operator provides runtime type information.
It returns a reference to a std::type_info object describing the type of an expression.

Use cases

Behavior

Example

#include <iostream>
#include <typeinfo>

struct Base { virtual ~Base() {} };
struct Derived : Base {};

int main() {
    Base* p = new Derived;

    std::cout << typeid(*p).name();  // "Derived"  (dynamic type)
    std::cout << typeid(p).name();   // "Base*"    (static type)
}

✔️ Returned object

typeid returns a std::type_info object, which supports: