I am writing small roguelike game where I spawn some items and put them into the std::list. Is this the right way to do it?
The Item class is as followed (I know it has public id property):
class Item {
public:
Item();
~Item();
unsigned int id;
};
Somewhere in the code I also defined:
list<Item*> listOfItems;
list<Item*>::iterator it;
Now I am using this code to create an item:
Item *p = new Item();
p->id = itemCrowbar;
listOfItems.push_back(p);
At the end of the program I use small loop to delete all items:
for (it = listOfItems.begin(); it!=listOfItems.end(); it++) {
delete *it;
}
Is this approach for creating objects, putting them in std::list and
at the end deleting them correct, or am I missing something important here?