Does the GotW #101 “solution” actually solve anything?

前端 未结 2 716
长发绾君心
长发绾君心 2020-11-27 06:51

First read Herb\'s Sutters GotW posts concerning pimpl in C++11:

  • GotW #100: Compilation Firewalls (Difficulty: 6/10)

  • GotW #101: Compilation

2条回答
  •  误落风尘
    2020-11-27 07:11

    You are correct; the example seems to be missing an explicit template instantiation. When I try to run the example with a constructor and destructor for widget::impl on MSVC 2010 SP1, I get a linker error for pimpl::pimpl() and pimpl::~pimpl(). When I add template class pimpl;, it links fine.

    In other words, GotW #101 eliminates all boilerplate from GotW #100, but you need to add an explicit instantiation of the pimpl<...> template with the implementation of the pimpl impl. At least with #101 the boiler plate you need is straightforward.

提交回复
热议问题