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
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);
}
}
}
}
};
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?