about summary refs log tree commit diff
path: root/cpptour/Vector.cc
diff options
context:
space:
mode:
authorNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-11-11 17:55:52 +0700
committerNguyễn Gia Phong <vn.mcsinyx@gmail.com>2019-11-11 17:55:52 +0700
commitb38d9929f7a015b56b847fde7e83f814f354497e (patch)
treedef6101df9623550d2d826831504ef93c54b0297 /cpptour/Vector.cc
parentcacc165173d67fa110766a555afe3020967d220c (diff)
downloadcp-b38d9929f7a015b56b847fde7e83f814f354497e.tar.gz
One does not simply do CP well in NNN
Diffstat (limited to 'cpptour/Vector.cc')
-rw-r--r--cpptour/Vector.cc23
1 files changed, 18 insertions, 5 deletions
diff --git a/cpptour/Vector.cc b/cpptour/Vector.cc
index aa09eef..8f94345 100644
--- a/cpptour/Vector.cc
+++ b/cpptour/Vector.cc
@@ -12,14 +12,27 @@ Vector::Vector (int s)
   sz = s;
 }
 
-double& Vector::operator[] (int i)
+Vector::Vector (initializer_list<double> lst)
+: elem {new double[lst.size()]}, sz {static_cast<int> (lst.size())}
 {
-  if (i < 0 || size() <= i)
-    throw out_of_range{"Vector::operator[]"};
-  return elem[i];
+  copy(lst.begin(), lst.end(), elem);
+}
+
+Vector::~Vector ()
+{
+  delete[] elem;
 }
 
-int Vector::size () noexcept
+int
+Vector::size () noexcept
 {
   return sz;
 }
+
+double&
+Vector::operator[] (int i)
+{
+  if (i < 0 || size() <= i)
+    throw out_of_range{"Vector::operator[]"};
+  return elem[i];
+}