What's the recommended signature of a getter method?
<p>Assume there is a need to implement getters/setters (also I try to avoid them whenever possible because they often indicate bad design). Which variant of the following two is better and what are the implications of each?</p>

<p>Possibility (1):</p>

<pre><code>class Foo;
class Bar
{
public:
    const Foo&amp; getFoo() const {return foo_;}
private:
    Foo foo_;
};
</code></pre>

<p>or (2):</p>

<pre><code>class Foo;
class Bar
{
public:
    void getFoo(Foo&amp; foo) const {foo = foo_}
private:
    Foo foo_;
};
</code></pre>

<p>Personally, I use always the first variant, because I find it more intuitive. In the second variant you have to construct the Foo object, which will hold the result of getFoo, before calling getFoo and then pass getFoo a reference to this object. This variant feels counterintuitive to me, but there are people, who prefer the secodn variant. For what reason might be the second variant superior to the first one?</p>
