The typeid
represents a C++ RTTI operator being also a C++ keyword. It returns a std::type_info
object that holds (dynamic) type specific information.
From what I understood from various sources, one MUST include <typeinfo>
when using typeid
, otherwise the program is ill-formed. In fact, my gcc5.2 compiler doesn't even compile the program if I don't include the before-mentioned header. I don't understand why is a header inclusion mandated for the usage of a C++ keyword. I understand mandating a header for whenever we use some object declared/defined in that header, but typeid
is not of a class type. So what is the reason behind this enforcement of including the header <typeinfo>
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…