Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- // Koenig lookup + explicit instantiation = access specifiers ko.
- // a modified version of a well known hack (C++standard/sutter/litb/dabrahams/...)
- // purpose is to deal with static private member functions and violate access specifiers
- // exercise is not about the access specifiers, but about where get() is actually found
- // compiles C++0x
- struct Victim {
- private:
- static int password()
- { return 1234; }
- };
- //
- template<typename T, int (*x)()>
- struct access_violator {
- constexpr friend decltype(x) get(T)
- { return x; }
- };
- struct access_proxy {
- typedef int (*type)();
- constexpr friend type get(access_proxy);
- };
- // explicit instantiation, won't work without it (disregards specifiers)
- template struct access_violator<access_proxy, &Victim::password>;
- int main() {
- // why is get() in global namespace ? :)
- printf("%d\n", (*get(access_proxy()))());
- }
Add Comment
Please, Sign In to add comment