fork(1) 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, typename tag >
  14. class access_bypass {
  15. friend type get( tag )
  16. { return value; }
  17. };
  18.  
  19. // Client code.
  20.  
  21. struct pcsi {};
  22. struct pci {};
  23. struct pcfi {};
  24.  
  25. int * get( pcsi );
  26. int c::* get( pci );
  27. void (c::* get( pcfi ) )( int );
  28.  
  29. template class access_bypass< int *, & c::si, pcsi >;
  30. template class access_bypass< int c::*, & c::i, pci >;
  31. template class access_bypass< void (c::*)( int ), & c::fi, pcfi >;
  32.  
  33. #include <iostream>
  34.  
  35. int main() {
  36. c a, b;
  37.  
  38. a.* get( pci() ) = 3;
  39. b.* get( pci() ) = 5;
  40. * get( pcsi() ) = 8;
  41.  
  42. std::cout << a.* get( pci() ) << ' ' << b.* get( pci() ) << ' ' << * get( pcsi() ) << '\n';
  43.  
  44. (a.* get( pcfi() ) )( 7 );
  45.  
  46. std::cout << a.* get( pci() ) << ' ' << b.* get( pci() ) << ' ' << * get( pcsi() ) << '\n';
  47. }
Success #stdin #stdout 0s 2896KB
stdin
Standard input is empty
stdout
3 5 8
7 5 7