2017-09-11 2 views
0

のための2つのtypeid式を比較:コンパイラエラートレーニングビデオから来て、このコードでは平等

#include <iostream> 

template<typename T> 
struct MyStruct { 
    T data; 
}; 

int main(void) 
{ 
    MyStruct<int> s; 
    s.data = 2; 
    assert(typeid(s.data) == typeid(int)); 
} 

が、私はこのコンパイラエラーを取得するには:

clang++ -std=c++14 class_templates.cpp 

class_templates.cpp:12:26: error: invalid operands to binary expression ('const std::type_info' and 'const std::type_info') 
    assert(typeid(s.data) == typeid(int)); 
      ~~~~~~~~~~~~~~^~~~~~~~~~~~ 

してコンパイル

編集:g ++でコンパイルした方が良いエラーになりました:

class_templates.cpp:14:20: error: must #include <typeinfo> before using typeid 
    assert(typeid(s.data) == typeid(int)); 
+3

あなたは '型IDを使用するためには、' 'の#include を使用する必要があります()'回答がそこに行く@Remy –

+0

-vvvvvvv – user0042

+0

@RemyLebeauのおかげ!それはそれを修正する。あなたはあなたのコメントを答えにすることができますか? – Scooter

答えて

関連する問題