How C++ `typeid` operator works

Queries information of a type.
Used where the dynamic type of a polymorphic object must be known and for static type identification.

int a = 0; 
std::string tname = typeid(a).name(); // tname == "i"

Static Type

Dynamic Type

~/p/how-typeid-op-works ❯❯❯ clang++ -std=c++17 test-typeid.cpp -g -fno-rtti test-typeid.cpp:15:10: error: use of typeid requires -frtti return typeid(foo).name(); ^

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store