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

标签 c++ typeid

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/

相关文章:

c++ - 创建与 C++11 随机 header 兼容的自定义分发

c++ - typeid 导致不同的编译器

c++ - 使用 RTTI 确定 C++ 中的继承图?

c++ - 在多态对象上使用 typeid 时,必须定义它吗?

c++ - 如何在 C++ 中键入

c++ - GCC 的 nm 列出了 method 的多个条目

c++/openFrameworks - 如何包含一个类

c++ - 在 C++ 中按文件填充数组或结构

c++ - 是否可以将 std::move 对象移出函数? (C++11)

c++ - 创建一个类型为 'this'/current object 的指针