title: Does storing a returned reference into a variable allow you to access that variable?
body: <p>I am confused as to why storing a reference to a member variable with an alias allows us to access it, while storing it with a variable does not allow us to access the same variable.</p>
  <p>Let me clear up what I mean, say we have class Journey:</p>
  <pre><code>class Journey {
    protected:
        Coordinate start; //coordinate consists of x and y values
    public:
        Journey(Coordinate startIn,): start(startIn){} 
    //methods ......
    Coordinate &amp; getStart(){ //returns a reference to the &quot;start&quot; member
      return start; 
    }
  };
  </code></pre>
  <ul>
  <li>now say I do this</li>
  </ul>
  <pre><code>int main() {
      Journey j(Coordinate(1,1));
      Coordinate &amp; a = j.getStart();  //function returns a reference and is stored under the alias &quot;a&quot;
      a.setX(0); //changes X value of the &quot;start&quot; member variable
      cout &lt;&lt; j.getStart().getX() &lt;&lt; endl; //returns 0 - as expected!
  }
  </code></pre>
  <ul>
  <li><p>the example above works as I returned a reference to the member variable &quot;start&quot; and stored it under an alias and I accessed it to change the original member variable</p>
  </li>
  <li><p><strong>But</strong> say I stored the reference to start under a variable instead</p>
  </li>
  </ul>
  <pre><code>int main() {
      Journey j(Coordinate(1,1));
      Coordinate a = j.getStart();  //function returns a reference and is stored under the VARIABLE &quot;a&quot;
      a.setX(0); 
      cout &lt;&lt; j.getStart().getX() &lt;&lt; endl; //returns 1 - Original start was not changed?
  }
  </code></pre>
  <ul>
  <li>I cannot do the same as a does not access the start member variable</li>
  </ul>
  <p>I am not sure why this happens? What happened behind the scenes? We are storing the reference to start under a <strong>variable</strong> instead of an <strong>alias</strong>.</p>