title: C++ - Return reference to a vector element
body: <p>I want to return a reference to a single element in a vector I get as param and then compare there memory addresses. A simplified example of my code is shown below:</p>
  
  <pre><code>const int &amp;test(std::vector&lt;int&gt; i) {
      return i.at(3);
  }
  
  TEST(test, all_test) {
      const std::vector&lt;int&gt; i = {1,2,3,4,5};
      const int &amp;j = test(i);
      ASSERT_THAT(&amp;j, Eq(&amp;i.at(3)));
  }
  </code></pre>
  
  <p>Using this I get the following error message:</p>
  
  <pre><code>Failure
  Value of: &amp;j
  Expected: is equal to 0x55da7899d4dc
    Actual: 0x55da7899d4fc (of type int const*)
  </code></pre>
  
  <p>How can I return reference to a single vector element?</p>