本文介绍了typeid没有返回正确的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

cout << typeid(int&).name();

我认为

应该以类型而不是int的形式返回int&,但是在GCC 4.5.1和VS2010 SP1 beta上,它会返回int.为什么会这样?

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?

推荐答案

这应该是typeid的工作方式.当将typeid应用于引用类型的 type-id 时,type_info对象引用引用的类型.

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.

ISO/IEC 14882:2003,5.2.8/4 [expr.typeid]:

ISO/IEC 14882:2003, 5.2.8 / 4 [expr.typeid]:

这篇关于typeid没有返回正确的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-10 21:44