16 #ifndef SIMPLEVECTOR_H
17 #define SIMPLEVECTOR_H
21 #define SPARE_CAPACITY 16
28 : m_size(0), m_capacity(initSize + SPARE_CAPACITY)
29 { m_objects =
new Object[m_capacity]; }
32 {
delete [] m_objects; }
34 int resize(
int newCapacity)
36 if(newCapacity < m_size)
39 Object *oldArray = m_objects;
41 m_objects =
new (std::nothrow) Object[newCapacity];
47 for(
int k = 0; k<m_size; k++)
48 m_objects[k] = oldArray[k];
50 m_capacity = newCapacity;
56 Object & operator[](
int index)
57 {
return m_objects[index]; }
59 const Object& operator[](
int index)
const
60 {
return m_objects[index]; }
69 {
return m_capacity; }
74 int push_back(
const Object& x)
76 if(m_size == m_capacity)
77 if (resize(m_capacity + SPARE_CAPACITY)<0)
79 m_objects[m_size++] = x;
95 #endif // SIMPLEVECTOR_H
Definition: simplevector.h:23