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