IDataObject : ambiguous symbol error

N

nicolas.hilaire

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.
 
H

Holger Grund

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
 
N

nicolas.hilaire

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 ...
 
H

Holger Grund

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top