C++/CLI - 命名空间和类的不明确符号
我尝试编译一个 C++/CLI 文件,其中包含一个头文件(本机、第三方),其中定义了类“Foo”。此外,我通过#using“Bar.dll”使用C# dll,其中定义了命名空间“Foo”。编译器给出错误 C2872“Foo 是不明确的符号”。
我不知道本机类“Foo”是在哪个命名空间中定义的,因为头文件中的类定义没有嵌套在某个命名空间中。所以我假设类“Foo”可能不在命名空间中(这在 C++ 中是可能的,不是吗?)。否则,我将指定类“Foo”及其名称空间,以使其特定于编译器。
我可以重命名“Bar.dll”中使用的命名空间“Foo”,但我正在寻找不同的解决方案来保留命名空间。实际上,类和命名空间是不同的元素 - 但我猜对于 c++/cli 编译器来说不是?
提前谢谢 米奇贝克
I try to compile a C++/CLI file, that is including a header file (native, third-party) wherein a class "Foo" is defined. Furthermore I am using a C# dll via #using "Bar.dll" wherein a namespace "Foo" is defined. The Compiler gives the Error C2872 "Foo is ambiguous symbol".
I dont know in which namespace the native class "Foo" is defined as the class defintion in the header file is not nested in a certain namespace. So I assume the class "Foo" might be in no namespace (that is possible in C++, isnt it?). Otherwise I would specify the class "Foo" with its namespace to make it specific for the compiler.
I have the possibility to rename the namespace "Foo" used in "Bar.dll" but I am looking for a different solution to keep the namespace. Actually a class and a namespace are different elements - but not for the c++/cli compiler I guess?
Thx in advance
Michbeck
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定这是否有效,但值得一试。
命名空间指令仅对命名空间有效,对类无效。对于 typedef 则反之亦然。您应该能够在代码中使用
FooClass
和FooNamespace
。I'm not sure if this will work, but it's worth a try.
The namespace directive is only valid on namespaces, not classes. Vise-versa with the typedef. You should be able to use
FooClass
andFooNamespace
in your code.除了类“Foo”的 typedef(由 David Yaw 提供)之外,还可以通过使用类“Foo”的全局命名空间来解决问题:::Foo。这样编译器就可以区分这个类和“Bar.dll”中的命名空间“Foo”
In addition to a typedef for the class "Foo" (Courtesy David Yaw) the problem can be solved by using the global namespace for the class "Foo": ::Foo . So the compiler can distinguish between this class and the namespace "Foo" in the "Bar.dll"
我遇到了类似的问题,有一个巨大的专有代码库,改变它的成本太高。当我尝试以下操作时,问题似乎突然出现:
我包含的代码恰好有自己的 Enum 类,如果您开始使用“System”命名空间,那么这两个名称会发生冲突。为了解决这个问题,我只需将其放在名称空间 { } 标题中。
这可能不适用于 #using 指令,但可能值得一试。
I've run into a similar problem with a huge proprietary codebase that would be too expensive to change. The issue seems to pop up for me when I try the following:
The code I'm including happens to have their own Enum class, and if you start using the "System" namespace, then the two names clash. To solve this, I simply put this inside of the namespace { } heading.
This might not work for the #using directive, but it might be worth a try.