fork(1) download
  1. #include <iostream>
  2.  
  3. template<typename Tag, typename Tag::type M>
  4. struct Rob {
  5. friend typename Tag::type get(Tag) {
  6. return M;
  7. }
  8. };
  9.  
  10.  
  11. using namespace std;
  12. class Point
  13. {
  14. public:
  15. Point( void ) : m_i(0) {}
  16. void PrintPrivate( void ){cout << m_i << endl; }
  17. private:
  18. int m_i;
  19. };
  20.  
  21. struct Point_f {
  22. typedef int Point::*type;
  23. friend type get(Point_f);
  24. };
  25. template struct Rob<Point_f, &Point::m_i>;
  26.  
  27. void ChangePrivate ( Point &i )
  28. {
  29. i.*get(Point_f()) = 4;
  30. }
  31.  
  32. int main()
  33. {
  34. Point sPoint;
  35. sPoint.PrintPrivate();
  36. ChangePrivate(sPoint);
  37. sPoint.PrintPrivate();
  38. }
Success #stdin #stdout 0.02s 2680KB
stdin
Standard input is empty
stdout
0
4