-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray.tpp
More file actions
75 lines (65 loc) · 1.19 KB
/
Copy pathArray.tpp
File metadata and controls
75 lines (65 loc) · 1.19 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#ifndef ARRAY_TPP
#define ARRAY_TPP
template<typename T>
Array<T>::Array() : _array(NULL), _size(0) {}
template<typename T>
Array<T>::Array(unsigned int n) : _array(NULL), _size(n)
{
if (n > 0)
_array = new T[n]();
}
template<typename T>
Array<T>::Array(const Array &other) : _array(NULL), _size(other._size)
{
if (_size > 0)
{
_array = new T[_size];
for (unsigned int i = 0; i < _size; i++)
_array[i] = other._array[i];
}
}
template<typename T>
Array<T> &Array<T>::operator=(const Array &other)
{
if (this != &other)
{
if (_array)
delete[] _array;
_size = other._size;
if (_size > 0)
{
_array = new T[_size];
for (unsigned int i = 0; i < _size; i++)
_array[i] = other._array[i];
}
else
_array = NULL;
}
return *this;
}
template<typename T>
Array<T>::~Array()
{
if (_array)
delete[] _array;
}
template<typename T>
T &Array<T>::operator[](unsigned int index)
{
if (index >= _size)
throw OutOfBounds();
return _array[index];
}
template<typename T>
const T &Array<T>::operator[](unsigned int index) const
{
if (index >= _size)
throw OutOfBounds();
return _array[index];
}
template<typename T>
unsigned int Array<T>::size() const
{
return _size;
}
#endif