fork download
  1. template <typename Tag> struct IntPair{
  2. int x, y;
  3.  
  4. IntPair& operator=(IntPair rhs){
  5. x = rhs.x; y = rhs.y;
  6. return *this;
  7. }
  8.  
  9. template <typename Other>
  10. IntPair& operator+=(const IntPair<Other>& rhs){ x += rhs.x; y += rhs.y; return *this; }
  11.  
  12. template <typename Other>
  13. const IntPair operator+(const IntPair<Other>& rhs) const { IntPair<Tag> result = *this; return result += rhs; }
  14. };
  15.  
  16. typedef IntPair<struct TagPosi> Position;
  17. typedef IntPair<struct TagSize> Size;
  18.  
  19. int main(){
  20. Size size = {10,10};
  21. Position pos = { 5, 5};
  22. pos += size;
  23. }
Success #stdin #stdout 0s 2824KB
stdin
Standard input is empty
stdout
Standard output is empty