为什么typeid返回的int和const int是相同的类型 [英] why typeid returns that int and const int are same types
本文介绍了为什么typeid返回的int和const int是相同的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
if(typeid(int) == typeid(const int))
cout << "Same types"<< endl;
程序输出:
相同类型
我错过了什么吗? 这些不是相同类型的大声笑.
am I missing something? these are not same types lol.
推荐答案
它们不是同一类型,但是typeid
运算符会除去const
和volatile
.
They aren't the same type, but the typeid
operator strips const
and volatile
.
来自5.2.8 [expr.typeid]
节:
glvalue表达式或作为
typeid
操作数的 type-id 的顶级 cv-qualifiers 始终被忽略.
The top-level cv-qualifiers of the glvalue expression or the type-id that is the operand of
typeid
are always ignored.
这篇关于为什么typeid返回的int和const int是相同的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文