title: static reference referring to temporary variable
body: <pre><code>#include &lt;iostream&gt;
  
  int getID ( int k ) {
      static int&amp; r = k;
      return r++;
  }
  
  int main()
  {
      int a = getID ( 10 );
      int b = getID ( 10 );
      std::cout &lt;&lt; "a = " &lt;&lt; a &lt;&lt; ", b = " &lt;&lt; b  &lt;&lt; std::endl;
      return 0;
  }
  </code></pre>
  
  <p>I don't understand why this code compiles.</p>
  
  <ol>
  <li>How is it possible for a static reference to refer to a local variable k, which will disappear in the end of the function call).</li>
  <li>On the second call we reinitialize the static reference with a new
  variable. Please explain what happens here, how come static
  REFERENCE can be "redefined" (i guess that i don't understand the
  meaning of a reference to a static variable inside a method).</li>
  </ol>