+ 1

How to examine type of something in c++ ?

In c++, are there any functions similar to... * "typeof(~)" in JavaScript * "type(~)" in Python * "~.class" in Ruby ?

31st Mar 2019, 2:12 PM
stilts
stilts - avatar
3 ответов
+ 3
typeid(~).name(); The output, however, depends on the compiler. Another trick you can use is to use a class template declaration without implementation and rely on an error message. template<typename T> class Z; auto a = 0; Z<decltype(a)> z; error: aggregate 'Z<int> z' has incomplete type and cannot be defined This error message is less cryptic than typeid(~).name() on gcc at least.
31st Mar 2019, 2:23 PM
Dennis
Dennis - avatar
+ 10
#include <typeinfo> cout << typeid(variable).name() << endl;
31st Mar 2019, 2:25 PM
Arushi Singhania
Arushi Singhania - avatar
+ 1
Thanks for answers ! I will try it!
31st Mar 2019, 3:52 PM
stilts
stilts - avatar