poly/unique/line.hpp

The following code example is taken from the book
C++17 - The Complete Guide by Nicolai M. Josuttis, Leanpub, 2017
The code is licensed under a Creative Commons Attribution 4.0 International License. Creative Commons License

// raw code

#ifndef LINE_HPP
#define LINE_HPP

#include "geoobj.hpp"
#include <iostream>

class Line : public GeoObj {
private:
  Coord from;
  Coord to;
public:
  Line (std::string n, Coord f, Coord t)
   : GeoObj{std::move(n)}, from{f}, to{t} {
  }

  virtual void move(Coord c) override {
    from += c;
    to += c;
  }
  virtual void draw() const override {
    std::cout << "line '" << name << "' from " << from
              << " to " << to << '\n';
  }

  [[nodiscard]] virtual std::unique_ptr<GeoObj> clone() const override {
    return std::make_unique<Line>(*this);
  }
};

#endif