1

pimpl idiom allows to reduce compilation dependencies in projects and have binary compatibility at the same time.

In other words you can change private implementation of a class without the need to recompile client's code.

Where can I find examples of such approach? Do you know any open source libraries or apps that uses it?

I know about QT and Poco:

fen
  • 8,812
  • 5
  • 29
  • 53
  • I've just found an older, similar question: https://stackoverflow.com/questions/8972588/is-the-pimpl-idiom-really-used-in-practice – fen Jan 05 '18 at 09:10

1 Answers1

2

Where can I find examples of such approach? Do you know any open source libraries or apps that uses it?

Qt. Specific module example: QGraphicsItem.cpp, filled with d_ptr. Private part interface. The whole thing with both public and private modules.

A private implementation makes a lot of sense in case of porting the whole library/framework to a different platform. You just put a different files for implementation in while keeping the public interface as is. And the implementation is accessible via d_ptr->.

For the curious: non-Qt Pimpl C++ 11 example.

Alexander V
  • 7,522
  • 4
  • 31
  • 41