title: Pimpl with unique_ptr : Why do I have to move definition of constructor of interface to ".cpp"?
body: <p>The code would work file as long as I don't move the definition of constructor (of <code>B</code>) to the header <code>B.h</code>.</p>
  
  <p><strong>B.h</strong></p>
  
  <pre><code>class Imp;  //&lt;--- error here
  class B{
      public:
      std::unique_ptr&lt;Imp&gt; imp;
      B();     //&lt;--- move definition to here will compile error
      ~B();
      //// .... other functions ....
  };
  </code></pre>
  
  <p><strong>B.cpp</strong></p>
  
  <pre><code>#include "B.h"
  #include "Imp.h"
  B::B(){ }
  ~B::B(){ }
  </code></pre>
  
  <p><strong>Imp.h</strong></p>
  
  <pre><code>class Imp{};
  </code></pre>
  
  <p><strong>Main.cpp</strong>  (compile me)</p>
  
  <pre><code>#include "B.h"
  </code></pre>
  
  <blockquote>
    <p>Error: deletion of pointer to incomplete type<br>
    Error: use of undefined type 'Imp' C2027</p>
  </blockquote>
  
  <p>I can somehow understand that the destructor must be moved to <code>.cpp</code>, because destructure of <code>Imp</code> might be called :-</p>
  
  <pre><code>delete pointer-of-Imp;  //something like this
  </code></pre>
  
  <p>However, I don't understand <strong>why the rule also covers constructor</strong> (question).        </p>
  
  <p>I have read :-</p>
  
  <ul>
  <li><a href="https://stackoverflow.com/questions/5606750/deletion-of-pointer-to-incomplete-type-and-smart-pointers">Deletion of pointer to incomplete type and smart pointers</a><br>
  describes reason why destructor need to be in <code>.cpp</code>.</li>
  <li><a href="https://stackoverflow.com/questions/9954518/stdunique-ptr-with-an-incomplete-type-wont-compile">std::unique_ptr with an incomplete type won&#39;t compile</a><br>
  warns about the default destructor.</li>
  </ul>