A little C++ help (vectors, pointers oh my!)

Associate
Joined
28 Sep 2003
Posts
1,724
Location
Leamington Spa
I've been slowly working on a simple RPG shop system for some work I've been given to do.

After lots of trial and error getting all my classes working, I finally think that bit works. Now I've reached the part where I need to add all these item classes to a vector, as an inventory for the shop and the player.

I've setup the vector thusly:

vector<Item*> inventory; // setup a vector for the agents inventory

Now, I've tried lots of things, but I just can't get my addItem function to work - not even worth pasting my code as it flat out doesn't work.

Basically, how should I go about making this work? I need it to accept a pointer to a created object, and add it to the inventory vector. If I can get this working, adding/remove/selling, should be easy.

Help :O
 
AtomicBanana said:
I've been slowly working on a simple RPG shop system for some work I've been given to do.

After lots of trial and error getting all my classes working, I finally think that bit works. Now I've reached the part where I need to add all these item classes to a vector, as an inventory for the shop and the player.

I've setup the vector thusly:

vector<Item*> inventory; // setup a vector for the agents inventory

Now, I've tried lots of things, but I just can't get my addItem function to work - not even worth pasting my code as it flat out doesn't work.

Basically, how should I go about making this work? I need it to accept a pointer to a created object, and add it to the inventory vector. If I can get this working, adding/remove/selling, should be easy.

Help :O


Could you post a small sample of code? There's lots of things you *might* be doing wrong - from your example i'd say you're trying to add an item by value into a vector thats expecting a pointer, but without seeing code its hard to be sure....
 
Back
Top Bottom