S SmartDocs
Serie: Server-Architecture-Firmware cpp 22 righe · Aggiornato 2026-02-03

RTTI.cpp

Server-Architecture-Firmware/RTTI.cpp

// Run-Time Type Identification (RTTI) is a feature in C++ that allows you to obtain the type information of an object during program execution. This can be useful when using dynamic typing, where the type of an object can change at runtime.

//! There are two main mechanisms for RTTI in C++:
    //Todo Typeid opeartor
    //Todo dynamic_cast operator

//? typeid operator
// typeid is an operator that returns a reference to an object of type type_info, which contains information about the type of the object. The header file <typeinfo> should be included to use typeid.

#include <iostream>
#include <typeinfo>
using namespace std;

int main(){
    int a = 20;
    float b = 10.5;
    char c = 'A';
    cout << "int a: " << typeid(a).name() << endl;
    cout << "float b: " << typeid(b).name() << endl;
    cout << "char c: " << typeid(c).name() << endl;
    return 0;
}

Articoli correlati