简体   繁体   中英

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 library 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".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM