-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray.cpp
More file actions
37 lines (30 loc) · 750 Bytes
/
Array.cpp
File metadata and controls
37 lines (30 loc) · 750 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
32
33
34
35
36
37
/*
I designed this array class because I could and because I might need it for an
odd school project. It has a similar interfact to the standard array, but it
does not yet have the ability to initialize with an initializer list. The
initializer list support may or may not be added in the future.
Copyright Christopher Almquist 2013
*/
#include "Array.h"
template<class T>
Array<T>::Array(int length)
{
p = (T*) ::operator new(sizeof(T) * (length + 1));
size = length;
}
template<class T>
Array<T>::~Array()
{
delete p;
}
template<class T>
int Array<T>::getSize()
{
return size;
}
template<class T>
T& Array<T>::at(int element)
{
assert(element >= 0 && element < size);
return *(p + element);
}