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>
?
<initializer_list>
also needs to be included in cases you may or may not expect. – Mytilenestd::initializer_list
, which makes a bit more sense, sincestd::initializer_list
is a class of its own, not a keyword, although implicitly used by the core language. – Hatbandauto list = {1, 2, 3};
andfor (auto x : {1, 2, 3}) {}
. – Mytileneinitializer_list
without the need to include the header. Which is more weird in a sense, sincelist
is now of an object typestd::initializer_list
. Ohh yes, you need to include it... Strange and ugly design imo. – Hatbandauto
. As for the second, there's this question. – Mytilenestd::nullptr_t
– Lammstd::nullptr_t
shall be defined as:typedef decltype(nullptr) nullptr_t;
" – Mytilene