Advertisement
Guest User

Untitled

a guest
Jan 25th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "Point.h"
  4.  
  5. namespace at {
  6.  
  7. template <typename T>
  8. class Point2D :
  9.   public Point < T > {
  10. public:
  11.   Point2D<T>() = default;
  12.   Point2D<T>(const T& xt_, const T& yt_) {
  13.     this->xt_ = xt_;
  14.     this->yt_ = yt_;
  15.   }
  16.   Point2D<T>(const Point<T>& other) {
  17.     assign(other);
  18.   }
  19.   ~Point2D<T>() = default;
  20.  
  21.   virtual void swap(Point<T>& other) override {
  22.     if (this != &other) {
  23.       Point2D<T> temp(*this);
  24.       *this = other;
  25.       other = temp;
  26.     }
  27.   }
  28.  
  29.   virtual void add(const Point<T>& other) override {
  30.     this->xt_ += other.getX();
  31.     this->yt_ += other.getY();
  32.   }
  33.  
  34.   virtual void assign(const Point<T>& other) override {
  35.     if (this != &other) {
  36.       this->xt_ = other.getX();
  37.       this->yt_ = other.getY();
  38.     }
  39.   }
  40.  
  41.   void setZ(const T& zt_) final {
  42.     assert(("Trying to set a Z coordinate from a Point2D", 0));
  43.   }
  44.  
  45.   const T& getZ() const final {
  46.     assert(("Trying to retrieve a Z coordinate from a Point2D", 0));
  47.     return zt_;
  48.   }
  49.  
  50.   friend Point2D<T> operator+(Point2D<T> lhs, const Point2D<T>& rhs) {
  51.     return lhs += rhs;
  52.   }
  53.  
  54. };
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement