title: Using vector::back() to modify vector element
body: <p>I have the following struct:</p>
  
  <pre><code>#include &lt;string&gt;
  #include &lt;vector&gt;
  
  struct A {
      std::string name;
      int id;
  };
  </code></pre>
  
  <p>And a vector containing A elements:</p>
  
  <pre><code>std::vector&lt;A&gt; a_vector;
  </code></pre>
  
  <p>I am trying to append an element to the vector and change its values using the following:</p>
  
  <pre><code>void test()
  {
      A a;
      get_a(a);
  
  //Up to this point I thought modifying this a object would mean modifying the back element of the vector. But it doesn't work as planned, doing this:
  
      a.id = 2; //Doesn't modify the id of the element in the vector. 
  }
  </code></pre>
  
  <p>where get_a is defined as : (The code is simplified, in the real one I really need to pass a as argument and not get it as return)</p>
  
  <pre><code>void get_a(A&amp; a) //This function normally assigns a in different ways
  {
      a_vector.emplace_back();
      a = a_vector.back();
  }
  </code></pre>
  
  <p>How can I do to have the a element be the same as the one in the vector? Do I really have to use pointers?</p>