Browse Source

constructor fix

Kajetan Johannes Hammerle 3 years ago
parent
commit
c5f5b3e525
2 changed files with 8 additions and 3 deletions
  1. 8 3
      Vector.h
  2. BIN
      Vector.zip

+ 8 - 3
Vector.h

@@ -21,7 +21,12 @@ public:
         }
     }
 
-    explicit Vector(int n) : Vector(n, T()) {
+    explicit Vector(int n) : Vector() {
+        // calling Vector(n, T()) would break structures which can be
+        // default constructed but not copied e.g. unique pointers elements
+        for(int i = 0; i < n; i++) {
+            push_back(T());
+        }
     }
 
     ~Vector() {
@@ -90,8 +95,8 @@ public:
 
     void resize(int size) {
         // calling resize(size, T()); would break structures which can be
-        // default constructed but not copied e.g. unique pointers elements will
-        // be equal to size after this call but not the capacity
+        // default constructed but not copied e.g. unique pointers elements
+        // will be equal to size after this call but not the capacity
         if(size > elements) {
             // fill until the given size is reached
             for(int i = elements; i < size; i++) {

BIN
Vector.zip