Can I combine setter and getter in one method, in C++?
<p>I would like to combine setter/getter in one method, in C++, in order to be able to do the following:</p>

<pre><code>Foo f;
f.name("Smith");
BOOST_CHECK_EQUAL("Smith", f.name());
</code></pre>

<p>I don't know how can I declare such a method inside <code>Foo</code> class:</p>

<pre><code>class Foo {
public:
  // how to set default value??
  const string&amp; name(const string&amp; n /* = ??? */) {
    if (false /* is it a new value? */) {
      _name = n;
    }
    return _name;
  }
private:
  string _name;
}
</code></pre>

<p>I'm looking for some elegant solution, with a true C++ spirit :) Thanks!</p>
