title: Modify in place the elements of a vector
body: <p>The following doesn't work as desired (print 2) because, I guess, the nodes are passed by value even though the vector is passed by reference. How could I fix it?</p>
  
  <pre><code>#include &lt;iostream&gt;
  using std::cout;
  using std::endl;
  
  #include &lt;vector&gt;
  using std::vector;
  
  class Node{
      public:
          int value;
          Node(int);
          void createChildren(vector&lt;Node&gt; &amp;);
  
  };
  
  //! constructor of a single node
  Node::Node(int value)
  {
      this-&gt;value = value;
  }
  
  void Node::createChildren(vector&lt;Node&gt; &amp;nodes)
  {
      for (int i = 0; i &lt; 5; i++) {
          Node n(0);
          nodes.push_back(n);
          if (i == 0) {
              value = nodes.size();
          }
      }
  }
  
  int main(void) {
      Node a(0);
      vector&lt;Node&gt; asdf;
      asdf.push_back(a);
      asdf[0].createChildren(asdf);
      cout &lt;&lt; asdf[0].value &lt;&lt; endl;
  
      return 0;
  }
  </code></pre>