Note that there are some explanatory texts on larger screens.

plurals
  1. PODoes the GotW #101 "solution" actually solve anything?
    primarykey
    data
    text
    <p>First read Herb's Sutters GotW posts concerning pimpl in C++11:</p> <ul> <li><p><a href="http://herbsutter.com/gotw/_100/" rel="noreferrer">GotW #100: Compilation Firewalls (Difficulty: 6/10)</a></p></li> <li><p><a href="http://herbsutter.com/gotw/_101/" rel="noreferrer">GotW #101: Compilation Firewalls, Part 2 (Difficulty: 8/10)</a></p></li> </ul> <p>I'm having some trouble understanding the solution proposed in GotW #101. As far as I can understand, all the problems laboriously solved in GotW #100 are back with a vengeance:</p> <ul> <li><p>The <code>pimpl</code> members are out-of-line templates, and the definitions are not visible at the point of use (in <code>class widget</code>'s class definition and implicitly generated special member functions of <code>widget</code>). There aren't any explicit instantiations either. This will cause unresolved external errors during linking.</p></li> <li><p><code>widget::impl</code> is still incomplete at the point where <code>pimpl&lt;widget::impl&gt;::~pimpl()</code> is <strike>instantiated</strike> defined (I don't think it actually IS instantiated at all, just referenced). So <code>std::unique_ptr&lt;widget::impl&gt;::~unique_ptr()</code> calls <code>delete</code> on a pointer to incomplete type, which produces undefined behavior if <code>widget::impl</code> has a non-trivial destructor.</p></li> </ul> <p>Please explain what forces the compiler to generate the special members in a context where <code>widget::impl</code> is complete. Because I can't see how this works.</p> <hr> <p>If GotW #101 still requires explicit definition of <code>widget::~widget()</code> in the implementation file, where <code>widget::impl</code> is complete, then please explain the "More Robust" comment (which @sehe quoted in his answer).</p> <p>I'm looking at the core claim of GotW #101 that the wrapper "eliminates some pieces of boilerplate", which seems to me (based on the remainder of the paragraph) to mean the <code>widget::~widget()</code> declaration and definition. So please don't rely on that in your answer, in GotW #101, that's gone!</p> <hr> <p>Herb, if you stop by, please let me know if it would be ok to cut+paste the solution code here for reference.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload