So, I have a class which stores a vector of pointers to objects. I have a method that adds objects to the vector. When adding, I know I can pass by reference or by pointer, and have read about the advantages and disadvantages of each, but in this case, I can't figure out which one is better and why. For all I can figure out, they're pretty much the same (but I'm probably wrong!)
Here's (a paraphrasing of) passing by pointer/address:
hpp:
class Room {
vector<Item*> items;
public:
void addItem(Item*);
};
cpp:
void Room :: addItem(Item* item) {
items.push_back(item);
}
...and pass by reference:
hpp:
class Room {
vector<Item*> items;
public:
void addItem(Item &);
};
cpp:
void Room :: addItem(Item &item) {
items.push_back(&item);
}
Which should I use?