this code does not compile but i don’t why, also the typeid() function can take int as input parameter so the problem must be related to the template mechanism but i don’t get the rationale behind this fail.
#include <iostream>
#include <typeinfo>
template<typename T> void func(T)
{
std::cout << typeid(T).name() << std::endl;
}
int main()
{
func(int);
return(0);
}
What is wrong with this template/code ?
You need to pass an instance of type
int, not the type itself:If you don’t want to pass an instance around, you could change your code like so: