title: How to return a reference to the reference passed in function argument?
body: <p>Ok, so what I'm trying to do is pass a reference to a function, then return that same reference without copying. I don't want to use move because that can "empty" the contents of the original variable. This is what I want in pseudo code</p>
  
  <pre><code>a;    
  b = func(a);    
  change(b); // a changes as well
  </code></pre>
  
  <p>I understand you can do this with pointers (   auto * b = &amp;a),
  but I want to see if it can be done with a function. This is what I tried:</p>
  
  <pre><code>#include &lt;vector&gt;
  #include &lt;iostream&gt;
  using namespace std;
  template&lt;class T&gt;
  T&amp; returnRef1(T* t){
      return *t;
  }
  template&lt;class T&gt;
  T&amp; returnRef2(T&amp; t){
      return t;
  }
  
  int main(){
      vector&lt;int&gt; vec1 = { 0, 1, 2, 3, 4 };
      auto * p2v = &amp;vec1;
      vector&lt;int&gt;  vec2 = returnRef1(p2v);
      vector&lt;int&gt; vec3 = returnRef2(vec1);
      vec2[0] = 1000;
      vec3[1] = 999;
      cout &lt;&lt; "vec1[0]=" &lt;&lt; vec1[0] &lt;&lt; " vec1[1]=" &lt;&lt; vec1[1] &lt;&lt; endl;
      cout &lt;&lt; "vec2[0]=" &lt;&lt; vec2[0] &lt;&lt; " vec2[1]=" &lt;&lt; vec2[1] &lt;&lt; endl;
      cout &lt;&lt; "vec3[0]=" &lt;&lt; vec3[0] &lt;&lt; " vec3[1]=" &lt;&lt; vec3[1] &lt;&lt; endl;
      cin.get();
  }
  </code></pre>
  
  <p>what prints</p>
  
  <pre><code>vec1[0]=0 vec1[1]=1
  vec2[0]=1000 vec2[1]=1
  vec3[0]=0 vec3[1]=999
  </code></pre>
  
  <p>what i want</p>
  
  <pre><code>vec1[0]=1000 vec1[1]=999
  vec2[0]=1000 vec2[1]=999
  vec3[0]=1000 vec3[1]=999
  </code></pre>
  
  <p>I understand that my vector is getting copied at some point(either in arguments and/or return) and I don't want that.</p>