Search code examples
c++-cliambiguous

C++/CLI - Ambiguous symbol of a namespace and a class


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


Solution

  • I'm not sure if this will work, but it's worth a try.

    namespace FooNamespace = Foo;
    typedef Foo FooClass;
    

    The namespace directive is only valid on namespaces, not classes. Vise-versa with the typedef. You should be able to use FooClass and FooNamespace in your code.