2012-01-17 41 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"; 
相關問題