Can't store Object into array correctly

I create a new object that holds an int:

Item newItem(1);

I can print out newItem's data:

cout << newItem.getData();

(prints 1)

I try to store it into an array that holds Items:
(that has already been initialized to hold 100 elements)

itemArray[itemArray.size()] = newItem;

When I try to print it out:

cout << itemArray[itemArray.size()].getData();

The console prints out some funky negative number, and not the actual data. I think I must be storing it incorrectly. How can I store the object correctly into the array?
Last edited on
arrays are indexed from array[ 0 ] to array[ array.size() - 1 ]
See fencepost error http://en.wikipedia.org/wiki/Off-by-one_error

You will need a loop to set all the elements of the array.
Topic archived. No new replies allowed.