From 029688e143109344989b1529259e391822abb0aa Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Sun, 21 Jul 2019 03:21:00 +0700 Subject: [cpptour] Learn the basis --- cpptour/Vector.cc | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 cpptour/Vector.cc (limited to 'cpptour/Vector.cc') diff --git a/cpptour/Vector.cc b/cpptour/Vector.cc new file mode 100644 index 0000000..aa09eef --- /dev/null +++ b/cpptour/Vector.cc @@ -0,0 +1,25 @@ +#include + +#include "Vector.h" + +using namespace std; + +Vector::Vector (int s) +{ + if (s < 0) + throw length_error{"You're being negetive!"}; + elem = new double[s]; + sz = s; +} + +double& Vector::operator[] (int i) +{ + if (i < 0 || size() <= i) + throw out_of_range{"Vector::operator[]"}; + return elem[i]; +} + +int Vector::size () noexcept +{ + return sz; +} -- cgit 1.4.1