If your goal is to hide implementation details from a client that sees only your header files (either for privacy or to exclude dependencies on internal library elements), the design template you are looking for is the pimpl template ("implementation pointer").
myclass.h:
class MyClassImpl; class MyClass { public: MyClass(); ~MyClass(); int someFunc(); private: MyClassImpl * pimpl; }
myclass.cpp:
class MyClassImpl { public: MyClassImpl(); int someFunc(); private:
Beware: This sample code does not have the correct copy semantics. Instead, you can use some kind of smart pointer or implement the correct constructor / assignment mechanism for the shenannigans operator.
source share