Created
August 4, 2012 17:54
-
-
Save marionette-of-u/3259020 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <map> | |
#include <typeinfo> | |
struct type_info_cmp{ | |
bool operator ()(const std::type_info *lhs, const std::type_info *rhs) const{ | |
return lhs->before(*rhs) != 0; | |
} | |
}; | |
struct a_type{ | |
virtual ~a_type(){} | |
}; | |
struct n_type{ | |
virtual ~n_type(){} | |
}; | |
struct b_type : a_type, n_type{ | |
virtual ~b_type(){} | |
}; | |
int main(){ | |
a_type a; | |
b_type b; | |
a_type *a_ptr = &a; | |
a_type *b_ptr = &b; | |
n_type *n_ptr = &b; | |
std::map<const std::type_info*, std::string, type_info_cmp> map; | |
map[&typeid(*a_ptr)] = "A"; | |
map[&typeid(*b_ptr)] = "B"; | |
map[&typeid(*n_ptr)] = "N"; // !! | |
// A, N | |
for(auto iter = map.begin(); iter != map.end(); ++iter){ | |
std::cout << iter->second << std::endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment