dynamic_array.hΒΆ
A header file containing the DynamicArray class definition.
- template <typename T>
- class DynamicArray
- #include <dynamic_array.h>
The class DynamicArray template class allows for the creation of a vector-like array of arbitrary member object type which may be dynamically resized. Standard vector class is not used to ensure minimal resizing occurs.
Public Functions
- DynamicArray()
Default constructor, creates empty object.
- DynamicArray(int size)
Parametrised constructor.
- Parameters
- size -
desired number of member objects
- size -
- DynamicArray(const DynamicArray & target)
Copy constructor.
- Parameters
- target -
DynamicArray object to copy
- target -
- void Resize(int new_length)
Resizes existing DynamicArray object by creating new object and swapping storage array addresses.
- Parameters
- new_length -
desired length for new array
- new_length -
- int Size(void) const
Access function.
- Return
- length of the array (number of member objects)
- T & operator[](int i)
Overloaded access operator to give traditional array-like interface.
- Return
- reference to argument pointer at target index
- Parameters
- i -
target index
- i -
- ~DynamicArray()
Default destructor, frees memory of internal storage array if any has been allocated.
Private Functions
- void SwapMemoryLocation(DynamicArray & target)
Function to swap the address in memory of two DynamicArray objects’ internal storage arrays.
- Parameters
- target -
DynamicArray object with which to swap internal storage arrays
- target -
Private Members
- T * array_
pointer to internal storage array
- int length_
length of the array (number of member objects)