Guest User

Untitled

a guest
Nov 25th, 2017
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. class Type1
  2. {
  3. public:
  4. template<typename T>
  5. Type& operator&(T t){t.serialize(*this);return *this;}
  6. template<>Type& operator&(int t){/*полезные действия*/return *this;}
  7. };
  8.  
  9. class Type2
  10. {
  11. public:
  12. template<typename T>
  13. Type& operator&(T t){t.serialize(*this);return *this;}
  14. template<>Type& operator&(int t){/*полезные действия*/return *this;}
  15. };
  16.  
  17. class C
  18. {
  19. int v;
  20.  
  21. template<typename T> friend T& T::operator&(C);
  22. template <class T> T& serialize(T&t){t&v; return t;}
  23. public:
  24. ...
  25. };
  26.  
  27. //------------------------------------------------------------------------------
  28. int _tmain(int argc, _TCHAR* argv[])//
  29. {
  30. Type t;
  31. C c;
  32. t & c & c & c;
  33. return 0;
  34. }
  35.  
  36. template<typename T> friend class T;
  37. friend Type& Type::operator&(class C);
  38. friend Type& operator&(class Type,class C);
  39. template<class T>friend T& class T::operator&(C);
  40. template<typename T> friend T& T::operator& < T > (class C);
  41.  
  42. class C
  43. {
  44. int v = 10;
  45.  
  46. template<typename T> friend T& operator&(T&, const C&);
  47. template <class T> T& serialize(T&t) const { t&v; return t; }
  48. };
  49.  
  50. template<typename T>
  51. T& operator&(T& t, const C& c)
  52. {
  53. c.serialize(t); return t;
  54. }
  55.  
  56. class Type1
  57. {
  58. public:
  59. Type1& operator&(int t) {/*полезные действия*/return *this; }
  60. };
  61.  
  62. class Type2
  63. {
  64. public:
  65. Type2& operator&(int t) {/*полезные действия*/return *this; }
  66. };
Add Comment
Please, Sign In to add comment