Skip to main content
gamedev.net
🔒 Locked

array of pointers

Started by Stef3d Jan 12, 2003 at 2:08 PM 1 replies 250+ views
Original Post
Stef3d
Stef3d
I am having trouble with keeping an inventory of objects. I have an array of pointers: Item *inventory[19]; and Item looks like: class Item { public: string name; }; but if i try to access it like this when the whole thing is not full: for(int x=0;x<=19;x++){ cout<name<
Brother Bob
Brother Bob
quote:

Item *inventory[19];
...
for(int x=0;x<=19;x++)


You''re allocating space for 19 pointers but the for loop goes through 20 elements. Bad.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.