gpt4 book ai didi

c++ - typeid 不返回正确的类型

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:53:43 25 4
gpt4 key购买 nike

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

在我看来,这应该返回 int& 作为类型,而不是 int,但是在 GCC 4.5.1 和 VS2010 SP1 beta 上它返回 整数。这是为什么?

最佳答案

这就是 typeid 应该如何工作的。当您将 typeid 应用于引用类型的 type-id 时,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.

关于c++ - typeid 不返回正确的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5151875/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com