去C++可以做什么当两个 Linux 第三方库在其枚举中使用相同的名称时

发布于 2024-10-08 22:48:24 字数 183 浏览 0 评论 0原文

我正在 Linux 上工作,使用第三方 C 和一堆第三方 C++ 代码,我正在编写我的 C++ 代码,但无法编译,因为编译器抱怨两次:

错误:冲突的声明 XXXX(我的变量姓名) 错误:XXXX 具有先前的十进制

XXXX 是第三方库的两个库内的两个不同枚举集中的枚举成员。

存在类似问题的案例不止一处。

I am working on Linux and using a third party C, and bunch of third party C++ code, and I am writing my C++ code and I can't compile because the compiler complains two times as such :

error: conflicting decalarations XXXX (my variable name)
error: XXXX has a previous decalratoin

XXXX is an enumeration member in two different enumeration sets within the two libraries of the third party libraries.

There are more than one cases that have the similar problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

厌倦 2024-10-15 22:48:24

您应该将 C 库标头包含在单独的命名空间中。

namespace foo {
    #include <foo.h>
}

这样,由于外部 C 代码不使用命名空间,程序仍将正确链接,但名称(在 C++ 级别)将不再与其他 C++ 库发生冲突。

You should include the C library header in a separate namespace.

namespace foo {
    #include <foo.h>
}

This way, because external C code does not use namespaces, the program will still link properly, but the names will (at the C++ level) not collide with your other C++ libraries any more.

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