I need to know a built-in function or anyway to get the type of a variable in C++
I want to check the type of the variable in a generic method.
for INSTANCE
template<class Numbers> bool Matrix(Numbers matrix[] ,int matrixsize)
{
if (/* type of matrix is int */)
return false;
else
return true;
}
New answer
For as far as my decryption skills go, the comments made the question slightly more clear. What you want is template specialization.
Old answer
If you want to do this at compile time, in C++11 you can use
decltypeto get the type of any expression:I’m not aware of any way to do this (easily) in C++03.
If you want to get the type of an object at runtime (which can be useful when dealing with polymorphism, sometimes), you can use the
typeid()operator andstd::type_info.