For example:
int a = 12;
cout << typeof(a) << endl;
Expected output:
int
The other answers involving RTTI (typeid) are probably what you want, as long as:
The alternative, (similar to Greg Hewgill's answer), is to build a compile-time table of traits.
template struct type_as_string;
// declare your Wibble type (probably with definition of Wibble)
template <>
struct type_as_string
{
static const char* const value = "Wibble";
};
Be aware that if you wrap the declarations in a macro, you'll have trouble declaring names for template types taking more than one parameter (e.g. std::map), due to the comma.
To access the name of the type of a variable, all you need is
template
const char* get_type_as_string(const T&)
{
return type_as_string::value;
}