title: Returning a class member reference variable results in runtime error
body: <p>For deductive reasons, I wrote a code as follows:</p>
  
  <pre><code>class Bike
  {
  public:
      Bike(std::string name) : m_name(name) {}
      std::string&amp; getName() const { return m_name; }
  private:
      std::string&amp; m_name;
  };
  
  int main() {
      string name("Trek");
      Bike bike(name);
  
      string&amp; ref1 = name;
      string&amp; ref2 = ref1;
      string&amp; ref3 = bike.getName(); // &lt;Error reading characters of string&gt; why?
  
      cout &lt;&lt; ref1 &lt;&lt; endl; // ok
      cout &lt;&lt; ref2 &lt;&lt; endl; // ok too
      cout &lt;&lt; ref3 &lt;&lt; endl; // Boom. runtime error
  
      return 0;
  }
  </code></pre>
  
  <p>Can someone please explain the reasons behind this behavior? </p>