Iterating through a template class's private, dynamic array from main
I have a template class which contains a private, dynamic array of its template type. What I'm trying to do is, from main, iterate through each of its array's elements and modify each of them.
So far I have accomplished this by making a pointer of the type the template class ends up using, and passing a reference to this pointer to a function in the template class which moves it to the next element. Then I just dereference the pointer in main and modify it. This is in a while loop that continues until all elements in the array have been covered.
But this seems like bad technique and I was wondering what a better way would be? It seems like I would at least need some kind of accessor function(s) in the template class, but it doesn't seem very encapsulationy to just have a getter that accepts an array index and return a reference to it.
Specifically, this is what I'm doing now:
In main I create a pointer of the type I'm using for the template class:
CustomerType *customerPointer = new CustomerType();
I then pass this to a function in the template class by reference (this is called in main):
Line.updateWaitTimes(customerPointer); (Line is the template object)
In the template class, I then modify the address the pointer holds:
customerPointer = &theArray[someIndex];
Back in main, I modify the object the pointer now points to:
(*customerPointer).incrementWaitTimes();
After this has looped through each customerType object in the array I delete customerPointer;
This is working, but seems poorly done, any help is appreciated.
EDIT: Also I can't call incrementWaitTime() inside the template class on each item in the array as the template class knows nothing about customerType objects (just accepts that as its template type)