I think that I am writing a static library. Let it have class Foo
// mylib.h
As you can see this library (let it be called mylib ) depends on another library. It compiles well. But when the user compiles his code (which uses Foo and includes mylib.h ) and links to my library, compilation fails because the user needs to have the dependency_header_from_other_static_library.h header file to compile the code.
I want to hide this dependency on the user. How can I do that? The only thing that comes to mind is the PIMPL idiom. How:
// mylib.h #include <dependency_header_from_other_static_library.h> class Foo { // ... private: class FooImpl; boost::shared_ptr<FooImpl> impl_; } // mylib_priv.h class FooImpl { // ... private: type_from_dependent_library x; }
But this requires that I duplicate the interface of the Foo class in FooImpl . And, do I use PIMPL in excess?
Thanks.
source share