title: smart pointers, typedefs and forward declarations
body: <p>I love using smart pointers, and have seen a bit of code which makes nice use of <code>typedef</code>s make make them prettier. For example:</p>
  
  <pre><code>struct A {
      typedef boost::shared_ptr&lt;A&gt; pointer;
  };
  </code></pre>
  
  <p>allows me to write: <code>A::pointer a(new A);</code></p>
  
  <p>But I have hit a minor snag in my <code>typedef</code> happiness :-/, forward declarations...</p>
  
  <p>So imagine this scenario:</p>
  
  <pre><code>struct B;
  struct A {
      boost::shared_ptr&lt;B&gt; b_;
  };
  
  struct B {
      boost::shared_ptr&lt;A&gt; a_;
  };
  </code></pre>
  
  <p>works well enough, but I'd love to clean that up a little. Unfortunately, this is <strong>doesn't work</strong></p>
  
  <pre><code>struct B;
  struct A {
      typedef boost::shared_ptr&lt;A&gt; pointer;
      B::pointer b_; // &lt;-- error here
  };
  
  struct B {
      typedef boost::shared_ptr&lt;B&gt; pointer;
      A::pointer a_;
  };
  </code></pre>
  
  <p>I understand why, at that point in the file, the compiler has no information that B in fact has a type in it named <code>pointer</code>.</p>
  
  <p>I have a feeling that I am stuck using the old approach at least for some stuff, but I'd love to hear some clever ideas.</p>