cout << typeid(int&).name();
This, in my opinion, should return int& as a type, not an int, but on GCC 4.5.1 and on VS2010 SP1 beta it returns int. Why is this?
int&
int
This is how typeid is supposed to work. When you apply typeid to a type-id of a reference type, the type_info object refers to the referenced type.
typeid
type_info
ISO/IEC 14882:2003, 5.2.8 / 4 [expr.typeid]:
When typeid is applied to a type-id, the result refers to a type_info object representing the type of the type-id. If the type of the type-id is a reference type, the result of the typeid expression refers to a type_info object representing the referenced type. If the type of the type-id is a class type or a reference to a class type, the class shall be completely-defined. Types shall not be defined in the type-id.
2.1m questions
2.1m answers
60 comments
57.0k users