不能在多个文件中包含动态库头文件吗?

发布于 2024-08-10 18:37:37 字数 75 浏览 3 评论 0原文

我已成功将动态库添加到程序中,但是当我尝试将头文件包含在项目的第二个文件中时,我收到有关类重新声明的错误。如果这还不够,我会添加更多信息

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

二手情话 2024-08-17 18:37:37

您需要将防护装置放入标头中,这样就不会多次包含它。对于文件“my.h”,您可以添加以下内容:

#ifndef MY_H
#define MY_H

// Header declarations here

#endif

这样,您可以多次包含 .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:

#ifndef MY_H
#define MY_H

// Header declarations here

#endif

This way, you can include the .h file multiple times but it will only be included the first time.

有木有妳兜一样 2024-08-17 18:37:37

#include 将用文件内容替换 #include 语句;因此,同一文件有多个 #include 将多次重新定义元素。典型的方法是像这样的保护措施:

/* file foo .h */
#ifndef _FOO_H
#define _FOO_H

/* content */

#endif

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:

/* file foo .h */
#ifndef _FOO_H
#define _FOO_H

/* content */

#endif
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文