Let me ask you what do you mean by "getting" the type?
You can actually use this type, for instance you may declare new variables of this type (as you demonstrate in your example), without explicitly specifying it.
Do you mean you want a textual description of the type?
If this is the case - there's no generic 100%-working way of doing it. This is because after compilation + link type and variable/function names vanish. They just don't exist at runtime.
You may however write some extra code to get the textual description of the types you need. One of the ways to do this:
template <typename T> const char* TypeName();
template <> const char* TypeName<int>() { return "int"; }
template <> const char* TypeName<double>() { return "double"; }
// ...
You'll get a linker error if you try to use TypeName
on a type whose name you didn't yet define. Then you'll have to add the appropriate template specialization of TypeName
.