Browse Source

more constructors

Kajetan Johannes Hammerle 3 years ago
parent
commit
5e3df48aec
1 changed files with 11 additions and 0 deletions
  1. 11 0
      Main.cpp

+ 11 - 0
Main.cpp

@@ -63,6 +63,15 @@ public:
     Vector() : data(nullptr), capacity(0), elements(0) {
     }
 
+    Vector(int n, const T& t) : Vector() {
+        for(int i = 0; i < n; i++) {
+            push_back(t);
+        }
+    }
+
+    Vector(int n) : Vector(n, T()) {
+    }
+
     ~Vector() {
         // placement new needs explicit destructor calling
         for(int i = 0; i < elements; i++) {
@@ -358,4 +367,6 @@ int main() {
     test();
     std::cout << "--------------------------\n";
     test<std::vector<A>>();
+
+    Vector<int> test(3);
 }