2012-01-17 38 views

回答

14

它们不是相同的类型,但是typeid操作条constvolatile

从节5.2.8 [expr.typeid]

顶层cv修饰符的glvalue表达的型-ID那就是typeid操作数总是被忽略。

3

你可能想要这个:

#include <type_traits> 

if (std::is_same<int, const int>::value) 
    std::cout << "same types\n"; 
else 
    std::cout << "different types\n"; 
相关问题