开发者

Header files repeatedly used in different header files in my static library

Since I got multiple classes and utility-functions I reuse on a regular basis, I started to create a static 开发者_如何学Golibrary for those parts.

Until now, most of those header files with class and function declarations #include the same "global" header file which itself #includes other header files (like <string> <windows.h> etc.).

As for me, It feels annoying to force a user to include more than one header file when only "actively" using the one which got the classes.

So I vanquished the global header file and included all the necessary headers into my own headers.

This worked in some way, but I encountered some problems regarding Winsock:

You need to #define WIN32_LEAN_AND_MEAN and ensure that the user won´t #include <windows.h> before those headers of mine, or multiple redefinitions will occur :/.

That´s why I wanted to ask You how You would do this? Or what approches You can think of?


I think you only have the option of defining a general header file that all other header files include and that defines WIN32_LEAN_AND_MEAN.

Otherwise you could instruct the user to include such definition in his own files, but his would be error prone.

As to inclusion of <windows.h> I think that it will not be included multiple times, since it has "include guards".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜