Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,
I need to use IDictionary in my project. When I add this compiler does not like it and report an obvious error
“error C2872: 'IDictionary' : ambiguous symbol” . However if I create a new sample project compiler never reports any error

Below is the code snippet

C++
Temp.h
#pragma once
#using "System.dll"

using namespace::System;
using namespace::System::Collections;
using namespace::System::Collections::Specialized;

public ref class MyCollection : public NameObjectCollectionBase  {

private:
   DictionaryEntry^ _de;

   // Gets a key-and-value pair (DictionaryEntry) using an index. 
public:
   property DictionaryEntry^ default[ int ]  {
      DictionaryEntry^ get(int index)  {
         _de->Key = this->BaseGetKey( index );
         _de->Value = this->BaseGet( index );
         return( _de );
      }
   }

   // Adds elements from an IDictionary into the new collection.
   MyCollection( IDictionary^ d )  {

      _de = gcnew DictionaryEntry();

      for each ( DictionaryEntry^ de in d )  {
         this->BaseAdd( (String^) de->Key, de->Value );
      }
   }

   // Removes an entry with the specified key from the collection. 
   void Remove( String^ key )  {
      this->BaseRemove( key );
   }

   // Removes an entry in the specified index from the collection. 
   void Remove( int index )  {
      this->BaseRemoveAt( index );
   }   
};


I am using VS2012
Posted
Updated 18-Jun-15 17:25pm
v2
Comments
Sergey Alexandrovich Kryukov 19-Jun-15 1:52am    
Use full type name for this interface, whatever it is, such as System::Collections::IDictionary.
But I would prefer using System::Collections::Generic.
—SA
Member 4201820 19-Jun-15 2:48am    
Hi,
Yeah you are right,
instead of IDictionary if I use "System::Collections::IDictionary" works fine.
need to do explicitly.
Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900