In your
push_back
method you have the following:
myscores[size] = values;
++size;
But you cannot assume that
myscores
is big enough to hold whatever number of values you are entering. You must check size to see if there is any space left in
myscores
. If it is close to overflowing then you need to expand it to allow further entries to be added.
So start by allocating some number of cells, and set capacity to that value. Then every time you add an item, check if size is equal to capacity. If so, allocate more space and adjust the two values for the next time.