c++ - How to include WinAPI without contaminating the rest of the code? -
i'm working on library in c++ , part of abstraction layer of several os functions need. started implementing windows api plan add together back upwards other platforms #ifdef , such.
what starting become problem including windows.h propagates whole rest of code don't need , especially, library, contaminate code of other people utilize it. wouldn't mind if windows api used namespace or clear way distinguish code instead #define lot of pretty mutual words such small, near, far (lowercase) , lot of function names pretty general.
so if platform specific part of code had access these , wouldn't included anywhere else. know obvious solution include windows.h in cpp files isn't possible because of platform specific info types or structures class fellow member variables such as:
class window { public: // ... private: hwnd handle; };
so there way accomplish this?
thanks.
use pimpl idiom ( http://en.wikipedia.org/wiki/opaque_pointer ). limitations of c++ programming language makes necessary utilize tricks in order info hiding.
one of ways of doing doing same way in c (where don't have problem @ all, because of following): forward-declare struct in header file , define contents in implementation file.
most people extracting entire private part of illustration own struct, contents defined in implementation file, , set pointer in header file, fellow member of private part of class.
also, #define win32_lean_and_mean before #include in order strip downwards windows.h gives you.
c++ winapi
No comments:
Post a Comment