title: C++ -- Adding elements to private member field std::vector
body: <pre><code>class T {
  private:
    std::vector&lt;T&gt; myVec;
    // ...
  public:
    T();
    T(float x, float y);
    std::vector&lt;T&gt; getMyVec() { return myVec; }
    // ...
  };
  </code></pre>
  
  <p>// in T.cpp I don't use myVec in any way (not in the constructor either)</p>
  
  <p>// in Tmain.cpp: </p>
  
  <pre><code>int main() {
    T myT;
    std::cout &lt;&lt; myT.getMyVec().size() &lt;&lt; std::endl; // 0
    T anotherT(1.1, 2.2);
    myT.getMyVec().push_back(anotherT);
    std::cout &lt;&lt; myT.getMyVec().size() &lt;&lt; std::endl; // 0
  }
  </code></pre>
  
  <p>Hopefully I can make myself clear (just assume that my #include's etc. are correct):</p>
  
  <p>So basically, I have a class <strong>T</strong> in which I have a private member field named <strong>myVec</strong> which is of type <strong>std::vector</strong>. I also have a public (get-)function to access that field.
  In main I create myself a T object, and print out its <strong>myVec.size()</strong>. It's zero as I haven't done anything to the vector yet. I create <strong>anotherT</strong> object and <strong>push_back()</strong> it to my vector field of the previous T object.
  Again I print out the <strong>myVec.size()</strong> of the former object (I expect it to be 1 at this point, as I've added <strong>anotherT</strong> to it. But it still returns 0 as its size. Why is that? And how can I make it so that it "saves" the objects I try to add to it? </p>