title: std::vector<>.size() throws exception
body: <p>i am trying to build a binary tree without pointers.
  A<code>std::vector&lt;NODE&gt;nodes</code>holds my Nodes.
  This is my node:</p>
  
  <pre><code>struct node {
    int bigger;
    int smaller;
    tuple data;
    std::vector&lt;node&gt; &amp;nodes_ref;
  
    node(tuple d, std::vector&lt;node&gt; &amp;nodes)
        : data(d), nodes_ref(nodes), smaller(0), bigger(0) {}
  
    bool insert(tuple in) {
      if (data == in)
        return false;
      else {
        if (data &gt; in) {
          if (smaller == 0) {
            node newNode(in, nodes_ref);
            nodes_ref.push_back(newNode);
            smaller = nodes_ref.size() - 1; // This is where the program is throwing an exception
            return true;
          } else
            return nodes_ref[smaller].insert(in);
        } else {
          if (bigger == 0) {
            node newNode(in, node_ref);
            nodes_ref.push_back(newNode);
            bigger = node_ref.size() - 1;
            return true;
          } else
            return node_ref[bigger].insert(in);
  </code></pre>
  
  <p>this is tree:</p>
  
  <pre><code>struct tree {
    std::vector&lt;node&gt; nodes;
  
    bool insert(tuple in) {
      if (nodes.size() == 0) {
        nodes.push_back(node(in, &amp;nodes));
        return true;
        else return nodes[0].insert(in);
      }
    }
  
    tree() { nodes.reserve(1000); }
  }
  </code></pre>
  
  <p>the main function:</p>
  
  <pre><code>int main() {
    tree t;
    t.insert(tuple(2,3);
  </code></pre>
  
  <p>When <code>node_ref.size()</code> is called a exception is being thrown.
  Yet everything should be fine there.
  What am i doing wrong ?</p>