Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,
Could you please help me to resolve below error.

error C2872: 'IComparer' : ambiguous symbol

My objective is to sort a List.
below is my code :
1) I have a list
C++
 // temp.h
List<smcsequipmentstatusinfo^>^ lsMCSEquipmentStatusInfo;
 So I created a class DeviceGroupComparer inherited from the interface IComparer as shown below

	public ref class DeviceGroupComparer: IComparer<smcsequipmentstatusinfo^>
	{
	public:
		virtual int Compare(SMCSEquipmentStatusInfo^ x, SMCSEquipmentStatusInfo^ y)
		{
			if (x == nullptr)
			{
				if (y == nullptr)
				{  
					return 0;
				}
				else
				{ 
					return -1;
				}
			}
			else
			{
				if (y == nullptr)
				{
					return 1;
				}
				else
				{
					int retval = x->strGroup->CompareTo(y->strGroup);

					if (retval != 0)
					{						
						return retval;
					}
					else
					{
						int retval1 = x->strDeviceNo->CompareTo(y->strDeviceNo);
						if (retval1 != 0)
						{
							return retval1;
						}
						else
						{
							return  x->strDeviceNo->CompareTo(y->strDeviceNo);;
						}						
						return x->strGroup->CompareTo(y->strGroup);
					}
				}
			}
		}
};

// temp. cpp
	DeviceGroupComparer^ DeviceGroup = gcnew DeviceGroupComparer();
        stClientInfo->lsMCSEquipmentStatusInfo->Sort(DeviceGroup);


in temp.cpp ,I just tried to show the way I tried to sort the list.

My observation:
If i select IComparer in "temp.h" and press f12 then in the find symbol result i find these :
interface class System::Collections::Generic::IComparer<t> - c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll
interface class System::Collections::IComparer - c:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll

I am not sure why its pointing to "System::Collections::Generic::IComparer<t>" and "class System::Collections::IComparer"
is it the reason of the error, if so then how can i fix it?
Posted
Updated 15-Jun-15 0:09am
v2
Comments
Sergey Alexandrovich Kryukov 15-Jun-15 15:27pm    
In what line?
—SA

Are you using the IComparer from System.Collections or System.Collections.Generic?

The compiler wants to know which one to use. Since the parameters to your Compare function are not Object, I'm guessing you want the latter.
 
Share this answer
 
CSS
Hi,
I want compiler to use IComparer from "using namespace System::Collections::Generic;"
hence in the header file I mentioned it.

but still I am not sure why compiler is confuse to get it either from
"using namespace System::Collections" or "using namespace System::Collections::Generic"
 
Share this answer
 

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