DotNet Visual C: IDataObject : ambiguous symbol error

  • nicolas_hilaire_motorola_com / 206 / Sat, 30 Jan 2010 18:27:00 GMT / Comments (3)
  • Hi group,

    when using unmanaged class with my managed app, I've seen errors when
    including (for example) <windows.h>.

    One of theses erros is :
    IDataObject : ambiguous symbol error

    I've seen somewhere that to avoid this error, i've to remove all "using
    namespace XXXXX" from .h, and move it to .cpp.

    This is working ... but, i would like to know why such an error ?

    Thanks in advance for any explanation

    Best,

    Nicolas H.

  • Keywords:

    idataobject, ambiguous, symbol, error, dotnet, visual, .net

  • http://dotnet.itags.org/visual-c/71205/«« Last Thread - Next Thread »»
    1. <nicolas.hilaire...motorola.com> wrote

      > when using unmanaged class with my managed app, I've seen errors when
      > including (for example) <windows.h>.
      > One of theses erros is :
      > IDataObject : ambiguous symbol error
      > I've seen somewhere that to avoid this error, i've to remove all "using
      > namespace XXXXX" from .h, and move it to .cpp.
      > This is working ... but, i would like to know why such an error ?
      Several distinct entities (probably types) named IDataObject
      from different scopes have been introduced into the current
      scope.

      Windows Shell declares an IDataObject as a native
      interface (=struct), the base class library has several
      definitions of IDataObject as a managed interface.

      All these types are different. When you say
      using namespace System::Windows::Forms
      IDataObject could refer to
      the IDataObject in the global scope (from objidl.h) or to
      System::Windows::Forms::IDataObject.

      You can use qualified names to refer to the entity.
      For instance,
      ::IDataObject // the one in the global scope
      System::Windows::Forms::IDataObject // the other one
      Windows::Forms::DataObject // same as above, assumes
      // using namespace System

      -hg

      holgergrund | Wed, 02 Jan 2008 19:18:00 GMT |

    2. i never use IDataObject for myself, but maybe it's used elsewhere

      But i can't understand why moving the references to the cpp files can
      solve this error ...

      nicolas_hilaire_motorola_com | Wed, 02 Jan 2008 19:19:00 GMT |

    3. <nicolas.hilaire...motorola.com> wrote

      >i never use IDataObject for myself, but maybe it's used elsewhere
      > But i can't understand why moving the references to the cpp files can
      > solve this error ...
      C and C++ are one-pass models. The compiler only considers
      the using directives that have already been seen.

      E.g.:
      class A{};
      namespace B { class A{}; }
      typedef A T; // OK
      using namespace B;
      typedef A U; // error ::A or ::B::A ?

      Since you say, you don't use IDataObject yourself and
      moving the directives to the .cpp makes things work
      again, I'd guess there's some header that references
      IDataObject, introducing the ambiguity.

      You should see where the error occurs by looking
      at the diagnostics (/showIncludes or preprocessing
      gives you additional information if you can't directly
      deduce the inclusion chain)

      Had you placed the using directives at the top of
      your .cpp file
      namespace System { namespace Windows { namespace Forms {
      }}}
      using namespace System::Windows::Forms
      #include ...
      you would have probably got the same errors.

      -hg

      holgergrund | Wed, 02 Jan 2008 19:20:00 GMT |