-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVector.cpp
More file actions
31 lines (25 loc) · 733 Bytes
/
Vector.cpp
File metadata and controls
31 lines (25 loc) · 733 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
* File: Vector.cpp
* Author: MackSix
*
* Created on November 11, 2015, 4:29 PM
*/
#include "Vector.h"
Vector::Vector(unsigned int s) : elem{new double[s]}, sz{s} // constructor: acquire resources
{
for (int i = 0; i != s; ++i) elem[i] = 0; // initialize elements
}
Vector::Vector(std::initializer_list<double> lst) // initialize with a list
: elem{new double[lst.size()]}, sz{static_cast<unsigned int>(lst.size())}
{
copy(lst.begin(), lst.end(), elem); // copy from lst into elem
}
Vector::~Vector() {
delete[] elem;
} // destructor: release resources
double& Vector::operator[](unsigned int i) {
return elem[i];
}
unsigned int Vector::size() const {
return sz;
}