title: dllexport'ing an incomplete class
body: <p>[EDIT: further digging revealed a different root issue. I'm rephrasing the question, but leaving the old version below, for consistency with the answer by @Leo]</p>
  
  <p>It seems VC++ (both under VS2005 &amp; VS2010) allows me to dllexport classes with missing implementations!  The following code builds fine:</p>
  
  <pre><code>// missingimp.h :
  class __declspec(dllexport) MissingImp
  {
    void DoStuff();   // no implementation anywhere
    void DoMoreStuff();  // neither for this
  }
  
  // missingimp.cpp
  #include "missingimp.h"
  </code></pre>
  
  <p>The code both compiles and links fine (in dll configuration) - and of course statically linking with the resulting dll fails.
  Is this be a bug? is this behavior somehow by design??</p>
  
  <p>[Old question:]</p>
  
  <p>I'm trying to dllexport a class, that has a data member templated on a forward-declared type:</p>
  
  <pre><code>// Class2Export.h:
  
  class ForwardDeclared ;
  
  template&lt;class T&gt; class TemplatedClass
  {
  T *m_ptr;
  
  public:
  TemplatedClass() { m_ptr-&gt;DoSomething(); }
  
  };
  
  class __declspec(dllexport) ExportedClass
  {
  TemplatedClass&lt;ForwardDeclared&gt; TemplateForward;
  };
  
  // Class2Export.cpp:
  
  #include "Class2Export.h"
  </code></pre>
  
  <p>(This is not a contrived example - in the real code TemplatedClass is a smart pointer, but that seems irrelevant to the issue at hand.)</p>
  
  <p>This code fails to compile, with -</p>
  
  <blockquote>
    <p>error C2027: use of undefined type
    'ForwardDeclared'</p>
  </blockquote>
  
  <p>That still makes some kind of sense, based on a <a href="https://connect.microsoft.com/VisualStudio/feedback/details/634361/problems-exporting-a-class-from-a-c-dll?wa=wsignin1.0#details" rel="nofollow">reply from MS</a>:</p>
  
  <blockquote>
    <p>If TemplatedClass has a constructor
    then a constructor will be
    automatically generated for
    ExportedClass. Since ExportedClass is
    exported the compiler tries to export
    the constructor but fails to generate
    code for it because ForwardDeclared is
    unknown.</p>
  </blockquote>
  
  <p>But I suspect that is not the ultimate answer, as when I declare (without even implementing!) a ctor for ExportedClass:</p>
  
  <pre><code>...
  class __declspec(dllexport) ExportedClass
  {
  ExportedClass();
  TemplatedClass&lt;ForwardDeclared&gt; TemplateForward;
  };
  ...
  </code></pre>
  
  <p>both compile <strong>and link</strong> succeed (with a due warning*).  The issue over at MS-connect seems abandoned - perhaps anyone can shed some light over this strange behaviour?</p>
  
  <p>Thanks!</p>
  
  <p>*EDIT: the generated warning is <a href="http://msdn.microsoft.com/en-us/library/esew7y1w.aspx" rel="nofollow">C4251</a> :
   class 'TemplatedClass ' needs to have dll-interface to be used by clients of class 'ExportedClass'</p>