#include #include template class Point { T x_; T y_; public: Point(T x, T y) :x_(x), y_(y) {} Point() :Point(T(),T()) {} T GetX() const {return x_;} T GetY() const {return y_;} }; template std::ostream &operator<<(std::ostream &out, const Point &pos) { out << "(" << pos.GetX() << ", " << pos.GetY() << ")"; return out; } //////////////////////////////////////////////////////////////// template class Polygon { std::vector< Point > points_; public: using value_type = T; using size_type = typename std::vector< Point >::size_type; using iterator = typename std::vector< Point >::iterator; using const_iterator = typename std::vector< Point >::const_iterator; size_type size() const { return points_.size(); } iterator begin() { return points_.begin(); } iterator end() { return points_.end(); } const_iterator begin() const { return points_.begin(); } const_iterator end() const { return points_.end(); } void push_back(const Point &pos) { points_.push_back(pos); } Point &operator[](size_type idx) {return points_[idx]; } const Point &operator[](size_type idx) const {return points_[idx]; } }; template std::ostream &operator<<(std::ostream &out, const Polygon &poly) { out << "Polygon[ "; for (const auto &pos : poly) { out << pos; out << " "; } out << "]"; return out; } //////////////////////////////////////////////////////////////// int main() { Point pos(1, 2); std::cout << pos << std::endl; Polygon poly; poly.push_back(Point(1, 2)); poly.push_back(Point(3, 4)); std::cout << poly << std::endl; for (auto cnt = 0U ; cnt < poly.size() ; cnt++) { std::cout << poly[cnt] << std::endl; } return 0; }