Compiler error when comparing two typeid expressions for equality -


on code comes training video:

#include <iostream>  template<typename t> struct mystruct {    t data; };  int main(void) {    mystruct<int> s;    s.data = 2;    assert(typeid(s.data) == typeid(int)); } 

i compiler error:

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

compiled with:

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

edit: had compiled g++ have gotten better error:

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

you must use #include <typeinfo> in order use typeid(), otherwise program ill-formed.

also see:

why need #include <typeinfo> when using typeid operator?


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -