Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Having trouble with a namespace and class type collision in C++/C# project

Having trouble with a namespace and class type collision in C++/C# project

Scheduled Pinned Locked Moved C / C++ / MFC
csharpquestionc++dotnet
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dxben
    wrote on last edited by
    #1

    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?

    B 1 Reply Last reply
    0
    • D dxben

      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?

      B Offline
      B Offline
      BadKarma
      wrote on last edited by
      #2

      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

      D 2 Replies Last reply
      0
      • B BadKarma

        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

        D Offline
        D Offline
        dxben
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • B BadKarma

          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

          D Offline
          D Offline
          dxben
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups