I'm working on an inventory system for a game. Right now I have:
Code:
Struct Item()
{
string name;
int value, quantity, type;
int creator(int);
};
int Item::creator(a)
{
if (a == 1)
{
Item potion;
potion.name = "Potion";
potion.value = 5;
potion.type = 1;
potion.quantity++;
}
}
So when the user buys, crafts, or finds a potion in the game, I will tell Item::Creator to make an object named potion, and assign its values. If the user where to use or sell all of their potions, should I have some code that will delete the potion object and its members to free up memory? Is that would I could use a destructor for? If so, how hard would it be to add a destructor in the above example?