gpt4 book ai didi

c++ - 为什么 typeid 返回 int 和 const int 是相同的类型

转载 作者:IT老高 更新时间:2023-10-28 22:58:59 27 4
gpt4 key购买 nike

if(typeid(int) == typeid(const int))
cout << "Same types"<< endl;

程序输出:

Same types

我错过了什么吗?这些不是相同的类型哈哈。

最佳答案

它们不是同一个类型,但是 typeid 运算符去掉了 constvolatile

从第 5.2.8 节 [expr.typeid]:

The top-level cv-qualifiers of the glvalue expression or the type-id that is the operand of typeid are always ignored.

关于c++ - 为什么 typeid 返回 int 和 const int 是相同的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8888960/

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