How does the pimpl idiom reduce dependencies?

前端 未结 7 2045
我在风中等你
我在风中等你 2020-12-10 05:35

Consider the following:

PImpl.hpp

class Impl;

class PImpl
{
    Impl* pimpl;
    PImpl() : pimpl(new Impl) { }
    ~PImpl() { delete pimpl; }
    vo         


        
7条回答
  •  执念已碎
    2020-12-10 06:20

    In your example, you can change the implementation of data without having to recompile the clients. This would not be the case without the PImpl intermediary. Likewise, you could change the signature or name of Imlp::DoSomething (to a point), and the clients wouldn't have to know.

    In general, anything that can be declared private (the default) or protected in Impl can be changed without recompiling the clients.

提交回复
热议问题