title: How to declare a self-referential container in C++?
body: <p>For a <code>typedef</code> of a <code>struct</code> in C, I can't do this:</p>
  
  <pre><code>typedef struct {
      unsigned id;
      node_t *left;
      node_t *right;
  } node_t;
  </code></pre>
  
  <p>because <code>node_t</code> is not known until it is defined, so it can't be used in its own definition. A bit of a Catch-22. However, I can use this workaround to make the desired self-referential type:</p>
  
  <pre><code>typedef struct node_s node_t;
  struct node_s {
      unsigned id;
      node_t *left;
      node_t *right;
  };
  </code></pre>
  
  <p>Similarly, I would like to do something like this for a C++ container referring to itself:</p>
  
  <pre><code>typedef pair&lt;unsigned, pair&lt;node_t *, node_t * &gt; &gt; node_t;
  </code></pre>
  
  <p>but of course, the compiler complains that it's never heard of <code>node_t</code> before it's defined <code>node_t</code>, as it would for the <code>struct typedef</code> above.</p>
  
  <p>So is there a workaround like for the <code>struct</code>? Or some better way to do this? (And no, I don't want to use <code>void</code> pointers.)</p>