<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://www.baszerr.eu/lib/exe/css.php?s=feed" type="text/css"?>
<rss version="2.0">
    <channel xmlns:g="http://base.google.com/ns/1.0">
        <title>BaSzErr - blog:2012:08:13</title>
        <description></description>
        <link>https://www.baszerr.eu/</link>
        <lastBuildDate>Wed, 06 May 2026 09:45:54 +0000</lastBuildDate>
        <generator>FeedCreator 1.8</generator>
        <image>
            <url>https://www.baszerr.eu/lib/exe/fetch.php?media=wiki:dokuwiki.svg</url>
            <title>BaSzErr</title>
            <link>https://www.baszerr.eu/</link>
        </image>
        <item>
            <title>1</title>
            <link>https://www.baszerr.eu/doku.php?id=blog:2012:08:13:1</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;pimpling_with_unique_ptr&quot;&gt;2012.08.13 - PImpling with unique_ptr&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
i&amp;#039;ve recently found an obvious, but a bit surprising, behavior of &lt;a href=&quot;https://en.wikipedia.org/wiki/C++11&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/C++11&quot;&gt;C++11&lt;/a&gt;&amp;#039;s &lt;a href=&quot;http://en.cppreference.com/w/cpp/memory/unique_ptr&quot; class=&quot;urlextern&quot; title=&quot;http://en.cppreference.com/w/cpp/memory/unique_ptr&quot; rel=&quot;ugc nofollow&quot;&gt;std::unique_ptr&amp;lt;&amp;gt;&lt;/a&gt;, when used as an internal holder for &lt;a href=&quot;https://en.wikipedia.org/wiki/Pimpl&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/Pimpl&quot;&gt;Pimpl&lt;/a&gt; object. well – in fact the problem is more general, but lets just take one step at a time… consider the following class:
&lt;/p&gt;
&lt;pre class=&quot;code cpp&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; MyClass
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt;
  MyClass&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  ~MyClass&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; doSth&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;private&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt;
  &lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; PImpl&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  std&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;unique_ptr&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;&amp;lt;&lt;/span&gt;PImpl&lt;span class=&quot;sy1&quot;&gt;&amp;gt;&lt;/span&gt; pimpl_&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
with some basic implementation, say:
&lt;/p&gt;
&lt;pre class=&quot;code cpp&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;class&lt;/span&gt; MyClass&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;PImpl&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
&lt;span class=&quot;kw2&quot;&gt;public&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt;
  PImpl&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw3&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;MyClass::PImpl::PImpl()&amp;quot;&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; endl&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
  ~PImpl&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw3&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;MyClass::PImpl::~PImpl()&amp;quot;&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; endl&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
  &lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; doSth&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw3&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;hello PImpl!&amp;quot;&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; endl&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
MyClass&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;MyClass&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt;
  pimpl_&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span class=&quot;kw3&quot;&gt;new&lt;/span&gt; PImpl &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&quot;kw3&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;MyClass::MyClass()&amp;quot;&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; endl&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
MyClass&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;~MyClass&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&quot;kw3&quot;&gt;cout&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;MyClass::~MyClass()&amp;quot;&lt;/span&gt; &lt;span class=&quot;sy1&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; endl&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; MyClass&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;doSth&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  pimpl_&lt;span class=&quot;sy2&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;&amp;gt;&lt;/span&gt;doSth&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
above example “hides” iostream from the user. let us use this class:
&lt;/p&gt;
&lt;pre class=&quot;code cpp&quot;&gt;&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; main&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  MyClass mc&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
code compiles, and prints:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;MyClass::PImpl::PImpl()
MyClass::MyClass()
MyClass::~MyClass()
MyClass::PImpl::~PImpl()&lt;/pre&gt;

&lt;p&gt;
as expected.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;2012.08.13 - PImpling with unique_ptr&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;pimpling_with_unique_ptr&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-1320&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;the_problem&quot;&gt;the problem&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
notice however, it was no accident, that we used non-const &lt;em&gt;unique_ptr&amp;lt;&amp;gt;&lt;/em&gt; – though this class is noncopyable, we want it to be movable. this pointer makes this for us. and so we write code to use it:
&lt;/p&gt;
&lt;pre class=&quot;code cpp&quot;&gt;MyClass makeObject&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  MyClass mc&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; mc&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;        &lt;span class=&quot;co1&quot;&gt;// &amp;lt;-- here is the problem - move does not work&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; main&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  MyClass mc&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt; makeObject&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
and compiler says something like this&lt;sup&gt;&lt;a href=&quot;#fn__1&quot; id=&quot;fnt__1&quot; class=&quot;fn_top&quot;&gt;1)&lt;/a&gt;&lt;/sup&gt;:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;MyClass.hpp:6:7: note: ‘MyClass::MyClass(const MyClass&amp;amp;)’ is implicitly deleted because the default definition would be ill-formed:
MyClass.hpp:6:7: error: use of deleted function ‘std::unique_ptr&amp;lt;_Tp, _Dp&amp;gt;::unique_ptr(const std::unique_ptr&amp;lt;_Tp, _Dp&amp;gt;&amp;amp;) [with _Tp = MyClass::PImpl; _Dp = std::default_delete&amp;lt;MyClass::PImpl&amp;gt;; std::unique_ptr&amp;lt;_Tp, _Dp&amp;gt; = std::unique_ptr&amp;lt;MyClass::PImpl&amp;gt;]’&lt;/pre&gt;

&lt;p&gt;
looks like that move c-tor was not taken into the consideration. copy c-tor is tried to be used instead, and it may not work (explicitly blocked by the &lt;em&gt;unique_ptr&amp;lt;&amp;gt;&lt;/em&gt;). this is when i was shocked – what is the problem? move c-tor is implicitly generated by the compiler. yes, unless it would be ill-formed…
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;the problem&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;the_problem&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:3,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;1321-2527&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit3&quot; id=&quot;the_solution&quot;&gt;the solution&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
the problem is, that on the &lt;em&gt;MyClass.hpp&lt;/em&gt; header level compiler does NOT know how to use &lt;em&gt;unique_ptr&amp;lt;PImpl&amp;gt;&lt;/em&gt; instances (this is why we moved &lt;em&gt;MyClass&lt;/em&gt;&amp;#039;s d-tor to the implementation file in the first place). since PImpl is only forward-declared, no code can be generated automatically. thus we need to provide move c-tor and move assignment operator ourselves, just like we did for c-tor and d-tor:
&lt;/p&gt;
&lt;pre class=&quot;code cpp&quot;&gt;&lt;span class=&quot;co1&quot;&gt;// MyClass.hpp:&lt;/span&gt;
MyClass&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;MyClass&lt;span class=&quot;sy3&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; other&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
MyClass&lt;span class=&quot;sy3&quot;&gt;&amp;amp;&lt;/span&gt; operator&lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;MyClass&lt;span class=&quot;sy3&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; other&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// MyClass.cpp:&lt;/span&gt;
MyClass&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;MyClass&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;MyClass&lt;span class=&quot;sy3&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; other&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;:&lt;/span&gt;
  pimpl_&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt; std&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;move&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt; other.&lt;span class=&quot;me1&quot;&gt;pimpl_&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
MyClass&lt;span class=&quot;sy3&quot;&gt;&amp;amp;&lt;/span&gt; MyClass&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;operator&lt;/span&gt;&lt;span class=&quot;sy1&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;MyClass&lt;span class=&quot;sy3&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; other&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  MyClass tmp&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt; std&lt;span class=&quot;sy4&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;move&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;other&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  swap&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;pimpl_, tmp.&lt;span class=&quot;me1&quot;&gt;pimpl_&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;sy2&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;kw3&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;sy4&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
this way we allow compiler to generate all the required methods of &lt;em&gt;unique_ptr&amp;lt;PImpl&amp;gt;&lt;/em&gt;, when needed.
&lt;/p&gt;

&lt;p&gt;
to toy around with above mentioned issue use this &lt;a href=&quot;https://www.baszerr.eu/lib/exe/fetch.php?media=blog:2012:08:13:pimpled_via_unique_ptr.tar.bz2&quot; class=&quot;media mediafile mf_bz2&quot; title=&quot;blog:2012:08:13:pimpled_via_unique_ptr.tar.bz2 (2.3 KB)&quot;&gt;sample code&lt;/a&gt;.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;the solution&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;the_solution&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:4,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;2528-3500&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit4&quot; id=&quot;afterword&quot;&gt;afterword&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
as mentioned at the beginning, the problem is more general. in fact it applies to all templates, instantiated with forward-declaration classes. in order to use it at all as such, their size must be known, thus they can hold pointer or reference to the instances of the parameter, at most. the thing is that problem is easily found when using this template as a member of other class, when the compiler wants to use (implicit) method, that requires full class body, of the template argument. PImpl is an excellent place to spot such an issue then. just keep in mind, it is far from last place you can find this issue.
&lt;/p&gt;

&lt;p&gt;
when i finally realized why my code does not compile i was amazed i haven&amp;#039;t seen it in the first place. it seems so obvious, yet there are few things to notice first… probably the most misleading part was the compiler error message. i hope &lt;a href=&quot;https://en.wikipedia.org/wiki/Clang&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/Clang&quot;&gt;Clang&lt;/a&gt;&amp;#039;s C++11-compliant release will make life simpler, by hitting the core of the problem, not just scratching its surface. for now keep in mind &lt;a href=&quot;https://en.wikipedia.org/wiki/Paulo Coelho&quot; class=&quot;interwiki iw_wp&quot; title=&quot;https://en.wikipedia.org/wiki/Paulo Coelho&quot;&gt;Paulo Coelho&lt;/a&gt;&amp;#039;s advise: &lt;em&gt;Be brave. Take risks. Nothing can substitute experience.&lt;/em&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;afterword&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;afterword&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:5,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;3501-4629&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit5&quot; id=&quot;ps&quot;&gt;ps&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
maybe a bit off topic, but worth mentioning, when talking about &lt;em&gt;unique_ptr&amp;lt;&amp;gt;&lt;/em&gt;, is the fact, that &lt;em&gt;unique_ptr&amp;lt;&amp;gt;&lt;/em&gt;, in its default deleter, has a protection against destroying forward-declared objects – something like &lt;a href=&quot;http://boost.sourceforge.net/libs/utility/checked_delete.html&quot; class=&quot;urlextern&quot; title=&quot;http://boost.sourceforge.net/libs/utility/checked_delete.html&quot; rel=&quot;ugc nofollow&quot;&gt;boost&amp;#039;s checked_delete&amp;lt;&amp;gt;&lt;/a&gt;. this makes destruction of forward-declared-only type instances impossible, preventing hard to track errors. nice work! :)
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;ps&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;ps&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:5,&amp;quot;secid&amp;quot;:5,&amp;quot;range&amp;quot;:&amp;quot;4630-&amp;quot;} --&gt;&lt;div class=&quot;footnotes&quot;&gt;
&lt;div class=&quot;fn&quot;&gt;&lt;sup&gt;&lt;a href=&quot;#fnt__1&quot; id=&quot;fn__1&quot; class=&quot;fn_bot&quot;&gt;1)&lt;/a&gt;&lt;/sup&gt; 
&lt;div class=&quot;content&quot;&gt;actual output is from gcc 4.7&lt;/div&gt;&lt;/div&gt;
&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Tue, 15 Jun 2021 20:09:10 +0000</pubDate>
        </item>
    </channel>
</rss>
