title: c++ weird behavior of constructors when using vector as the class private variable
body: <p>First of all I am sorry for this silly question, but I am new to the world of C++ and I am used to Java and Python.</p>
  
  <p>I would like to ask how are constructors supposed to work in C++. I would expect that if I assign some value or sub-object to my instance then it will not be deleted by another constructor?</p>
  
  <p>Particularly my problem is following: </p>
  
  <p>I have class Tree that looks like this:</p>
  
  <pre><code>class Tree {
     Node * const first;
     Node * last;
     std::vector&lt;Node *&gt; nodesVector;
     unsigned int nodes;
  
  public:
     Tree(Node * const root) : first(root){
         nodes = 1;
         nodesVector.push_back(root);
     }
  }
  </code></pre>
  
  <p>And then I have class RRTStar that looks like this:</p>
  
  <pre><code>class RRTStar {
     Tree * tree;
     Node * root;
     const double RADIUS;
  
  public:
     RRTStar(const Point &amp; point, double radius) : RADIUS(radius){
         Node n;
         n.point = point;
         unsigned int zero = 0;
         n.id = zero;
         n.cost = 0;
         n.parent = NULL;
         this-&gt;root = &amp;n;
         Tree t = Tree(this-&gt;root);
         this-&gt;tree = &amp;t;
     }
  }
  </code></pre>
  
  <p>As you can see there is always appended one value to the vector from the Tree's constructor which is called from RRTStar constructor. When I go through debug I can see that there is really added the Node n to the vector, but unfortunately it is then somehow deleted after the RRTStar constructor finishes.</p>
  
  <p>So my question is what am I doing wrong that vector or it's content of the tree instance is deleted? </p>