+ 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 ?
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.
+ 10
#include <typeinfo>
cout << typeid(variable).name() << endl;
+ 1
Thanks for answers !
I will try it!