You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
812 B
C++

#pragma once
#include "iterators.h"
class IShape {
IShape* next = nullptr;
IShape* prev = nullptr;
public:
virtual ~IShape() = default;
virtual void draw() const = 0;
virtual double area() const = 0;
void set_next(IShape* n) {
next = n;
if (n) n->prev = this;
}
IShape* get_next() const { return next; }
IShape* get_prev() const { return prev; }
template<typename Policy>
Traversal<IShape, Policy> traverse() {
return Traversal<IShape, Policy>(this);
}
using forward = IteratorForward<IShape>;
using backward = IteratorBackward<IShape>;
};
class Circle : public IShape {
double r;
public:
Circle(double radius) : r(radius) {}
void draw() const override {
std::cout << "Drawing Circle of radius " << r << "\n";
}
double area() const override {
return 3.14159 * r * r;
}
};