title: How to best deal with C++ classes that need to have an object of self type?
body: <p>I'm a beginner in C++ with some experience in other programming languages (i.e. Python, Javascript).
  I have a couple of questions concerning "recursive" classes - classes that are declared within themselves - in C++.</p>
  
  <h2>Question 1</h2>
  
  <p>For a class with constructor, I understand that declaring it within itself, would cause its declaration to be incomplete and thus the compiler would have no way of working out the size of its objects.
  I learned thus far that a class declaration can only contain a <strong>pointer to self type</strong> or <strong>a static object of self type</strong>.
  However, I don't understand what the <strong>benefits</strong> are to either approach? My goal is to use a class much like a tree structure/network, where each node stores its parent node and child nodes! </p>
  
  <h2>Question 2</h2>
  
  <p>Both parent and child nodes would be set with class functions. How do I declare self types within a function of the same class? Do I also use static or pointers? How do I initialise correctly in this case? </p>
  
  <h3>example.cpp</h3>
  
  <pre class="lang-cpp prettyprint-override"><code>#include "Point.hpp"
  
  class Node {
      //Node parent; // ERROR
  
      // Option 1: Pointer
      Node * parent;
  
      // Option 2: Static
      static Node parent;
  
      vector&lt;Node&gt; children;
  
  public:
      Node(float _x, float _y, float _z);
      void setChildren(/* some params */);
  
      float x, y, z;
  };
  </code></pre>
  
  <h3>example.hpp</h3>
  
  <pre class="lang-cpp prettyprint-override"><code>Node::Node(float _x, float _y, float _z) {
      x = _x;
      y = _y;
      z = _z;
  }
  
  void Node::setChildren(/* some params */) {
      Node child1, child2; // ERROR: how to declare here?
  
      // do stuff with the parameters...
  
      child1 = {/*x1, y1, z1*/}; // ERROR: how to initialise?
      child2 = {/*x2, y2, z2*/}; // ERROR: how to initialise?
      children.push_back(child1);
      children.push_back(child2)
  </code></pre>
  
  <p>I hope somebody can explain this to me! I'm really lost here.</p>
  
  <p>Thanks! Any help is greatly appreciated.</p>