// simple_vector.h: simple vectors - probably wouldn't want to use in real code // based on Stroustrup, A Tour of C++ (2014), p. 37 #include class AbstractContainer { public: virtual double& operator[](int index) = 0; virtual int size() = 0; virtual ~AbstractContainer() { } }; class FixedVector : public AbstractContainer { public: FixedVector(int size) : elements{new double[size]}, _size{size} { for(int i = 0; i < size; ++i) elements[i] = 0.0; } ~FixedVector() { delete [] elements; } int size() override { return _size; } double& operator[](int index) override { if ( index < 0 || index >= _size ) throw std::out_of_range("Illegal index into vector."); return elements[index]; } private: int _size; // debugging trick: put first for visibility double *elements; };