Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2013
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. template<typename Tag>
  4. struct result {
  5.     /* export it ... */
  6.     typedef typename Tag::type type;
  7.     static type ptr;
  8. };
  9.  
  10. template<typename Tag>
  11. typename result<Tag>::type result<Tag>::ptr;
  12.  
  13. template<typename Tag, typename Tag::type p>
  14. struct rob : result<Tag> {
  15.     /* fill it ... */
  16.     struct filler {
  17.         filler() { result<Tag>::ptr = p; }
  18.     };
  19.     static filler filler_obj;
  20. };
  21.  
  22. template<typename Tag, typename Tag::type p>
  23. typename rob<Tag, p>::filler rob<Tag, p>::filler_obj;
  24.  
  25. struct A {
  26. private:
  27.     void f() {
  28.         std::cout << "шах и мат, атеисты!" << std::endl;
  29.     }
  30. };
  31.  
  32. struct Af { typedef void(A::*type)(); };
  33. template class rob<Af, &A::f>;
  34.  
  35. int main(int argc, char *argv[])
  36. {
  37.     A a;
  38.     (a.*result<Af>::ptr)();
  39.  
  40.     getchar();
  41.  
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement