Having trouble with a namespace and class type collision in C++/C# project
-
I have a C++ app that includes a 3rd party library that has a type called 'System'. This class exists in a namespace, let's call it XYZ::System. Then I am compiling my C++ app with /clr and somehow when VC8 includes xlocale (which in turn uses a macro defined in yvals.h) that calls a method in .NET (System.bla.bla) there is an ambiguity. How can I resolve this easily?
-
I have a C++ app that includes a 3rd party library that has a type called 'System'. This class exists in a namespace, let's call it XYZ::System. Then I am compiling my C++ app with /clr and somehow when VC8 includes xlocale (which in turn uses a macro defined in yvals.h) that calls a method in .NET (System.bla.bla) there is an ambiguity. How can I resolve this easily?
Hi, You probably used the using directive the simplefy the usage of the System class like this:
using namespace XYZ; void Function() { System obj; ... }
This indeed conflicts with the System Namespace of .Net. In this case you will have to remove the using directive and use the System class like this:
void Function() { XYZ::System obj; ... }
Or If the third party library is a type library like the ado objects then you could try to use the rename directive and change the System class while importing the type library like this:
#import "XYZ.dll" rename("System", "XSystem") ... using namespace XYZ; void Function() { XSystem obj; ... }
Hope this solves your problem codito ergo sum
-
Hi, You probably used the using directive the simplefy the usage of the System class like this:
using namespace XYZ; void Function() { System obj; ... }
This indeed conflicts with the System Namespace of .Net. In this case you will have to remove the using directive and use the System class like this:
void Function() { XYZ::System obj; ... }
Or If the third party library is a type library like the ado objects then you could try to use the rename directive and change the System class while importing the type library like this:
#import "XYZ.dll" rename("System", "XSystem") ... using namespace XYZ; void Function() { XSystem obj; ... }
Hope this solves your problem codito ergo sum
Thanks, the 3rd party library is actually a static lib but I do have the source to it. So I guess I can go through it and do a replace on "System" to make it "XYZ::System". Is it possible to use #import on a .lib file? That would be easier but I guess its not that big a deal, one find and replace should do the trick.
-
Hi, You probably used the using directive the simplefy the usage of the System class like this:
using namespace XYZ; void Function() { System obj; ... }
This indeed conflicts with the System Namespace of .Net. In this case you will have to remove the using directive and use the System class like this:
void Function() { XYZ::System obj; ... }
Or If the third party library is a type library like the ado objects then you could try to use the rename directive and change the System class while importing the type library like this:
#import "XYZ.dll" rename("System", "XSystem") ... using namespace XYZ; void Function() { XSystem obj; ... }
Hope this solves your problem codito ergo sum
Alright I tried to simply add XYZ:: to all instances of System in the headers of the 3rd party library , but I realized that the problem is with microsoft's yvals.h usage of System.bla.bla when I've included XYZ as a namespace. It's not working. I am going to have to rename and rebuild the entire 3rd party library, and everything that uses it.. What a major pain in the neck.