Programming own collection class - page 2

 
Ovo:

This part is a bit weird (inconsistent) from my point of view.

void add(Order& order)
{
.....
  orders[(size - 1)] = GetPointer(order);
}
 
Order* order = new Order();
....
orders.add(order);

 I would code it as

void add(Order* order)
{
.....
  orders[(size - 1)] = order;
}
They both do the same thing with your add(new). But the former allows the call to work with either a pointer or an instance.
Order globalOrder;
:
add(globalOrder);
as opposed to
Order globalOrder;
:
add( GetPointer(globalOrder) ); // Why does the caller need to know
                                // add internally stores a pointer?

I would code it thus:
void add(Order& order){ add( GetPointer(order) ); }
void add(Order* order) ...
        int pointer;
        int size;
       
        void OrderCollection()
        {
            pointer = -1;
            size = 0;
        }
Get in the habit of using initialization lists. Initialize once instead of default initialization and then assign.
        int pointer;
        int size;
       
        void OrderCollection()
                  : pointer(-1),
                    size(0)
                      {/*nothing more needs to be done*/}
 
WHRoeder:


They both do the same thing with your add(new). But the former allows the call to work with either a pointer or an instance.as opposed to
I would code it thus:

I did not state it did not work. I have little use for collections with static instances, but if you have it different, I have no problem with it.
Reason: