title: Type aliases and incomplete types
body: <p>I'm probably over reaching here to solve what should be a simple problem.  I started this question here:
  <a href="https://stackoverflow.com/questions/17735852/getting-type-of-a-base-class-at-compile-time-in-c" title="Getting type of a base class at compile time">Getting type of base class at compile time</a></p>
  
  <p>Basically I'm trying to make the class manage it's own pointer types.  I'm wrapping a C library where some structures have reference counting embedded in them, and others do not.  Those that don't, I'd like to use shared_ptr.  Those that do, I'd like to use intrusive_ptr.  I'd like to avoid relying on programmer intellect to ensure the use of the proper wrapper.  Eventually, I'd like to add more capability that relies on this behavior, but I'm not there yet.</p>
  
  <p>@Yakk came up with an interesting solution using template type aliases, and I've tried to implement it.  Unfortunately I've got myself in a spot where I can't seem to resolve circular references to the compiler's satisfaction.  I get an "incomplete type 'Test2' named in nested name specifier" error pointing to the "using pointer=" line.  I also get a bizarre "definition differs from declaration in return type" for my definition of Test::f(), but I suspect that might resolve itself once I get the first error resolved.</p>
  
  <p>Most of the references I find on this error type involve sequencing of header files, but even with everything in one file I can't figure out how to order things to make this problem go away.</p>
  
  <p>Any ideas?</p>
  
  <pre class="lang-cpp prettyprint-override"><code>#include &lt;iostream&gt;
  #include &lt;memory&gt;
  
  
  template&lt;typename T&gt;
  class Pointered: public std::enable_shared_from_this&lt;T&gt;
  {
  public:
      using pointer=std::shared_ptr&lt;T&gt;;     //&lt;-- incomplete type named error
      using weakPointer = std::weak_ptr&lt;T&gt;;
  };
  
  
  template&lt;typename T&gt;
  using Ptr =  typename T:: pointer;
  
  template&lt;typename T&gt;
  using WkPtr = typename T:: weakPointer;
  
  
  class Test2;
  
  class Test:public Pointered&lt;Test&gt;
  {
  public:
      Ptr&lt;Test2&gt; f();
  };
  
  
  class Test2:public Pointered&lt;Test2&gt;
  {
  public:
      Ptr&lt;Test&gt; p;
      Test2(Ptr&lt;Test&gt; ptr):p(ptr){}
  };
  
  
  int main(int argc, const char * argv[])
  {
      Ptr&lt;Test&gt; p=std::make_shared&lt;Test&gt;();
      Ptr&lt;Test&gt; p3=p;
      p-&gt;f();
      std::cout &lt;&lt; "Refcount: " &lt;&lt; p.use_count() &lt;&lt; std::endl;
  }
  
  
  //definition differs from declaration in return type error here
  Ptr&lt;Test2&gt; Test::f()
  {
      return Ptr&lt;Test2&gt;(new Test2((Ptr&lt;Test&gt;)shared_from_this()));
  }
  </code></pre>