我的静态库中的不同头文件中重复使用的头文件
由于我定期重用多个类和实用函数,因此我开始为这些部分创建一个静态库。
到目前为止,大多数带有类和函数声明的头文件#include 相同的“全局”头文件
,它本身#includes
其他头文件(例如< string>
等)。
对我来说,当用户只“主动”使用获取类的头文件时,强制用户包含多个头文件感觉很烦人。
因此,我放弃了全局头文件,并将所有必要的头文件包含到我自己的头文件中。
这在某种程度上有效,但我遇到了一些有关 Winsock
的问题:
您需要 #define WIN32_LEAN_AND_MEAN
并确保用户不会 #include
在我的那些标头之前,否则会发生多次重新定义:/。
这就是为什么我想问你你会怎么做?或者你能想到什么方法?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您只能选择定义所有其他头文件都包含的通用头文件,并定义 WIN32_LEAN_AND_MEAN。
否则,您可以指示用户将此类定义包含在他自己的文件中,但他很容易出错。
至于包含
我认为它不会被多次包含,因为它有“包含防护”。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".