Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int a = 12;
- cout << typeof(a) << endl;
- int
- cout << typeid(a).name() << endl;
- #include <iostream>
- #include <typeinfo>
- using namespace std;
- int main() {
- int i;
- cout << typeid(i).name();
- return 0;
- }
- template <typename T> const char* typeof(T&) { return "unknown"; } // default
- template<> const char* typeof(int&) { return "int"; }
- template<> const char* typeof(float&) { return "float"; }
- MyNamespace::CMyContainer<int, test_MyNamespace::CMyObject>
- // MSVC 2003:
- class MyNamespace::CMyContainer[int,class test_MyNamespace::CMyObject]
- // G++ 4.2:
- N8MyNamespace8CMyContainerIiN13test_MyNamespace9CMyObjectEEE
- #include <iostream>
- using namespace std;
- template <typename T> class type_name {
- public:
- static const char *name;
- };
- #define DECLARE_TYPE_NAME(x) template<> const char *type_name<x>::name = #x;
- #define GET_TYPE_NAME(x) (type_name<typeof(x)>::name)
- DECLARE_TYPE_NAME(int);
- int main()
- {
- int a = 12;
- cout << GET_TYPE_NAME(a) << endl;
- }
- template <typename T> struct type_as_string;
- // declare your Wibble type (probably with definition of Wibble)
- template <>
- struct type_as_string<Wibble>
- {
- static const char* const value = "Wibble";
- };
- template <typename T>
- const char* get_type_as_string(const T&)
- {
- return type_as_string<T>::value;
- }
Add Comment
Please, Sign In to add comment