fork download
  1. // Target class.
  2.  
  3. class c {
  4. static int si;
  5. int i;
  6. void fi( int arg ) { si = i = arg; }
  7. };
  8.  
  9. int c::si;
  10.  
  11. // Library code.
  12.  
  13. template< typename type, type value, type & receiver >
  14. class access_bypass {
  15. static struct mover {
  16. mover()
  17. { receiver = value; }
  18. } m;
  19. };
  20.  
  21. template< typename type, type value, type & receiver >
  22. typename access_bypass< type, value, receiver >::mover
  23. access_bypass< type, value, receiver >::m;
  24.  
  25. // Client code.
  26.  
  27. int *pcsi;
  28. int c::*pci;
  29. void (c::*pcfi)( int );
  30.  
  31. template class access_bypass< int *, & c::si, pcsi >;
  32. template class access_bypass< int c::*, & c::i, pci >;
  33. template class access_bypass< void (c::*)( int ), & c::fi, pcfi >;
  34.  
  35. #include <iostream>
  36.  
  37. int main() {
  38. c a, b;
  39.  
  40. a.* pci = 3;
  41. b.* pci = 5;
  42. * pcsi = 8;
  43.  
  44. std::cout << a.* pci << ' ' << b.* pci << ' ' << * pcsi << '\n';
  45.  
  46. (a.* pcfi)( 7 );
  47.  
  48. std::cout << a.* pci << ' ' << b.* pci << ' ' << * pcsi << '\n';
  49. }
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
3 5 8
7 5 7