1 #include "stdafx.h"
2
3 #include "kryString.h"
4 #include "kryArray.h"
5
6 template <class T, class RT>
kryArray()7 kryArray<T,RT>::kryArray() : m_count(0), m_capacity(10)
8 {
9 this->m_array = new T[m_capacity];
10 }
11
12 template <class T, class RT>
kryArray(int capacity)13 kryArray<T,RT>::kryArray(int capacity) : m_count(0), m_capacity(capacity)
14 {
15 this->m_array = new T[m_capacity];
16 }
17
18 template <class T, class RT>
~kryArray()19 kryArray<T,RT>::~kryArray()
20 {
21 delete [] this->m_array;
22 }
23
24 template <class T, class RT>
Resize(int new_size)25 void kryArray<T,RT>::Resize(int new_size)
26 {
27 T *new_array = new T[new_size];
28 for(int i = 0; i < this->m_count; i++)
29 new_array[i] = this->m_array[i];
30
31 delete [] this->m_array;
32 this->m_array = new_array;
33 }
34
35 template <class T, class RT>
Add(T obj)36 void kryArray<T,RT>::Add(T obj)
37 {
38 if(this->m_capacity == this->m_count)
39 this->Resize(this->m_capacity * 2);
40
41 this->m_array[this->m_count] = obj;
42 this->m_count++;
43 }
44
45 template <class T, class RT>
GetCount()46 int kryArray<T,RT>::GetCount()
47 {
48 return this->m_count;
49 }
50
51 template <class T, class RT>
operator [](int index)52 RT kryArray<T,RT>::operator [](int index)
53 {
54 return this->m_array[index];
55 }
56
57
58 template class kryArray<kryString>;
59 template class kryArray<int>;
60
61