简体   繁体   English

Header 文件在我的 static 库中的不同 header 文件中重复使用

[英]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.由于我定期重用多个类和实用程序函数,因此我开始为这些部分创建一个 static 库。

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.). 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.至于我,强迫用户包含多个 header 文件时只“主动”使用获得课程的文件,这感觉很烦人。

So I vanquished the global header file and included all the necessary headers into my own headers.所以我征服了全局 header 文件,并将所有必要的头文件包含到我自己的头文件中。

This worked in some way, but I encountered some problems regarding Winsock :这在某种程度上起作用,但我遇到了一些关于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:/.您需要#define WIN32_LEAN_AND_MEAN并确保用户不会在我的这些标题之前#include <windows.h> ,否则会发生多次重新定义:/。

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.我认为您只能选择定义所有其他 header 文件包含并定义 WIN32_LEAN_AND_MEAN 的通用 header 文件。

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".至于包含<windows.h>我认为它不会被多次包含,因为它具有“包含守卫”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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