| Код | #include <map> #include <vector> using namespace std;
bool deref_equal(int *lhs, int *rhs) { return *lhs == *rhs; } bool deref_less(int *lhs, int *rhs) { return *lhs < *rhs; }
class С { private: const vector<int *> *V; public: С(const vector<int *> *V) : V(V) {} bool operator==(const С &rhs) const { return std::equal(V->begin(), V->end(), rhs.V->begin(), deref_equal); // Сравнение } bool operator<(const С &rhs) const { return std::lexicographical_compare(V->begin(), V->end(), rhs.V->begin(), rhs.V->end(), deref_less); } };
int _tmain(int argc, _TCHAR* argv[]) { map<С, int> m;
int a=10, b=20; vector<int*> v; v.push_back(&a); v.push_back(&b);
int aa=10, bb=20; vector<int*> vv; v.push_back(&aa); v.push_back(&bb);
bool f1 = ( m.find(С(&v)) == m.end() ); // find m[&v]; bool ff = ( m.find(С(&vv)) == m.end() ); // find bool f2 = ( m.find(С(&v)) == m.end() ); // find }
|
При поиске используется сравнение из стандартной библиотеки вместо моего. Для friend bool operator==(const C &lhs , const C &rhs) то же самое. Почему так происходит и как исправить? |