Return by reference or create a typical setter/getter?
<p>I was wondering about good practices in C++, and I was facing the problem of making a getter/setter for a class member.</p>

<p>So, why don't simply return the member by reference so this way I can modify or access its value to read it? Specifically, this is my code:</p>

<pre><code>class Chest : public GameObject
{
public:
    Chest();
    ~Chest();

    static int&amp; num_chests();

private:
    static int num_chests_;
};
</code></pre>

<p>Is this a bad practice? Should I use these instead?</p>

<pre><code>class Chest : public GameObject
{
public:
    Chest();
    ~Chest();

    static int num_chests();
    static void set_num_chests(int num_chests);

private:
    static int num_chests_;
};
</code></pre>
