const reference public member to private class member - why does it work?
<p>Recently, I found an interesting discussion on how to allow read-only access to private members without obfuscating the design with multiple getters, and one of the suggestions was to do it this way:</p>

<pre><code>#include &lt;iostream&gt;

class A {
public:
  A() : _ro_val(_val) {}
  void doSomething(int some_val) {
    _val = 10*some_val;
  }
  const int&amp; _ro_val;
private:
  int _val;
};

int main() {
  A a_instance;
  std::cout &lt;&lt; a_instance._ro_val &lt;&lt; std::endl;
  a_instance.doSomething(13);
  std::cout &lt;&lt; a_instance._ro_val &lt;&lt; std::endl;
}
</code></pre>

<p>Output:</p>

<pre><code>$ ./a.out 
0
130
</code></pre>

<p><a href="http://www.gotw.ca/gotw/066.htm" rel="nofollow" title="GotW#66">GotW#66</a> clearly states that object's lifetime starts </p>

<blockquote>
  <p>when its constructor completes successfully and returns normally. That is, control reaches the end of the constructor body or an earlier return statement.</p>
</blockquote>

<p>If so, we have no guarantee that the <code>_val</code> memeber will have been properly created by the time we execute <code>_ro_val(_val)</code>. So how come the above code works? Is it undefined behaviour? Or are primitive types granted some exception to the object's lifetime?</p>

<p>Can anyone point me to some reference which would explain those things?</p>
