Is the pImpl idiom really used in practice?

后端 未结 11 1310
渐次进展
渐次进展 2020-11-22 17:21

I am reading the book \"Exceptional C++\" by Herb Sutter, and in that book I have learned about the pImpl idiom. Basically, the idea is to create a structure for the p

11条回答
  •  失恋的感觉
    2020-11-22 17:42

    Agree with all the others about the goods, but let me put in evidence a limit: doesn't work well with templates.

    The reason is that template instantiation requires the full declaration available where the instantiation took place. (And that's the main reason you don't see template methods defined into CPP files)

    You can still refer to templetised subclasses, but since you have to include them all, every advantage of "implementation decoupling" on compiling (avoiding to include all platoform specific code everywhere, shortening compilation) is lost.

    Is a good paradigm for classic OOP (inheritance based) but not for generic programming (specialization based).

提交回复
热议问题