How to return member that can be changed?
<p>Multi thread enviroment . The content of Foo can be multi thread.</p>

<pre><code>class Foo
{
public:
   const A &amp; getA() {return a_;} //has guard
   void setA(A newA){a_ = newA;} //has guard

private:
    A a_;
};
</code></pre>

<p>caller:</p>

<pre><code>A a  = foo.getA();
</code></pre>

<p>in another question that i asked someone told me that 
<a href="http://herbsutter.com/2008/01/01/gotw-88-a-candidate-for-the-most-important-const/" rel="nofollow">If you return const&amp; it's guaranteed that life time of variable will be prolonged to lifetime of the reference</a>
, so according to this i dont need to copy the value and i safe even if call to setA on foo done right after i call to getA, but a lot of argument against it was araised , so i feel that this is not correct.</p>

<p>I want to be on the safe side so i change the signature to be :</p>

<pre><code>A &amp; getA() {return a_;}
</code></pre>

<p>but the compiler still give me warning that i have reference to local variable. i dont understand why, because as far as i understand (new to cpp) the return value is a copy of foo.a, so what the problem with this?</p>

<p>i am not worried about change of a_ content.(_a.age =4) . i worry about call to set and that my 'a' in the caller will be illegal</p>
