about summary refs log tree commit diff
path: root/cpptour/Vector.cc
diff options
context:
space:
mode:
Diffstat (limited to 'cpptour/Vector.cc')
-rw-r--r--cpptour/Vector.cc25
1 files changed, 25 insertions, 0 deletions
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 <stdexcept>
+
+#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;
+}