if(typeid(int) == typeid(const int))
cout << "Same types"<< endl;
Run Code Online (Sandbox Code Playgroud)
计划产出:
相同的类型
我错过了什么吗?这些是不同类型大声笑.
Ben*_*igt 14
它们不是同一类型,但typeid操作员剥离const和volatile.
从5.2.8节[expr.typeid]:
glvalue表达式的顶级cv限定符或作为操作数的type-id
typeid始终被忽略.
你可能想要这个:
#include <type_traits>
if (std::is_same<int, const int>::value)
std::cout << "same types\n";
else
std::cout << "different types\n";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2644 次 |
| 最近记录: |