C++ Pass by reference vs. pointer in a Class
<p>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!)</p>

<p>Here's (a paraphrasing of) passing by pointer/address:</p>

<pre><code>hpp:
class Room {
    vector&lt;Item*&gt; items;
public:
    void addItem(Item*);
};

cpp:
void Room :: addItem(Item* item) {
    items.push_back(item);
}
</code></pre>

<p>...and pass by reference:</p>

<pre><code>hpp:
class Room {
    vector&lt;Item*&gt; items;
public:
    void addItem(Item &amp;);
};

cpp:
void Room :: addItem(Item &amp;item) {
    items.push_back(&amp;item);
}
</code></pre>

<p>Which should I use?</p>
