Сначала о предмете вопроса. Есть вот такая программа:
#pragma warning(disable: 4786)
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <utility>
using namespace std;
class CKey {
public:
bool operator<(const CKey& right) const {
if (f1<right.f1 && f2<right.f2)
return true;
else
return false;
}
bool operator==(const CKey &right) const {
if (f1==right.f1 && f2==right.f2)
return true;
else
return false;
}
/*CKey& operator=(const CKey& right) {
f1=right.f1;
f2=right.f2;
return *this;
}*/
CKey(){}
CKey(int a, int b) : f1(a), f2(b) {}
public:
int f1;
int f2;
};
class CCompare {
bool operator() (CKey& t1,CKey t2) {
if (t1==t2)
return true;
else
return false;
}
};
typedef multimap<CKey, int> tagData;
tagData data;
void main()
{
for(int i=1; i<=10; i++)
data.insert(make_pair(CKey(i,i), i));
tagData::iterator it;
for(it=data.begin(); it!=data.end(); ++it)
cout << it->first.f1 << "." << it->first.f2 << endl;
CKey k(-6,6);
it=data.find(k); //(1)
//it=find(data.begin(), data.end(), k); //(2)
if (it==data.end())
cout << "Not find" << endl;
else
cout << "Find" << endl;
}
В таком виде она выдает, что ключ найден. Почему?
Если CKey(6,-6), то ключ также найден, а если CKey(-6,-6), то не найден.
На вызов (2) компилятор (VC6) выдает ошибку
c:\program files\microsoft visual studio\vc98\include\algorithm(43) : error C2784:
'bool __cdecl std::operator ==(const class std::basic_string<_E,_Tr,_A> &,const _E *)'
: could not deduce template argument for 'const class std::basic_string<_E,_Tr,
_A> &' from 'struct std::pair<class CKey const ,int>' Почему?
Что я сделал не так?
Спасибо за помощь.