不能在多个文件中包含动态库头文件吗?
我已成功将动态库添加到程序中,但是当我尝试将头文件包含在项目的第二个文件中时,我收到有关类重新声明的错误。如果这还不够,我会添加更多信息
I have successfully added a dynamic library to a program, but when I try to include the header file in a second file of the project I get errors about class redeclaration. I will add more info if this isn't enough
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将防护装置放入标头中,这样就不会多次包含它。对于文件“my.h”,您可以添加以下内容:
这样,您可以多次包含 .h 文件,但只会在第一次包含它。
You need to put guards into your header so it isn't included multiple times. For file 'my.h', you can add something along the lines of:
This way, you can include the .h file multiple times but it will only be included the first time.
#include 将用文件内容替换 #include 语句;因此,同一文件有多个 #include 将多次重新定义元素。典型的方法是像这样的保护措施:
An #include will replace the #include statement with the files content; having multiple #include's of the same file will therefore redefine the elements multiple times. The typical way is a safeguard like: