Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > C/C++: Общие вопросы > stl_algo.h: error: no match for operator==


Автор: Delen 16.8.2013, 15:03
Получаю ошибку в коде:
Код

/usr/lib/gcc/i686-pc-linux-gnu/4.5.4/include/g++-v4/bits/stl_algo.h: In function '_InputIterator std::__find(_InputIterator, _InputIterator, const _Tp&, std::input_iterator_tag) [with _InputIterator = std::_Rb_tree_iterator<std::pair<const call_id, int> >, _Tp = call_id]':
/usr/lib/gcc/i686-pc-linux-gnu/4.5.4/include/g++-v4/bits/stl_algo.h:4209:45:   instantiated from '_IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = std::_Rb_tree_iterator<std::pair<const call_id, int> >, _Tp = call_id]'
main.c:70:95:   instantiated from here
/usr/lib/gcc/i686-pc-linux-gnu/4.5.4/include/g++-v4/bits/stl_algo.h:131:7: error: no match for 'operator==' in '__first.std::_Rb_tree_iterator<_Tp>::operator* [with _Tp = std::pair<const call_id, int>, _Tp& = std::pair<const call_id, int>&]() == __val'

 Пришлось выделить проблемный блок в тестовую программу, не могу понять в чем дело, оператор == есть. Помогите найти ошибку.
Код

struct call_id {

        bool operator<(const call_id  &other) const
        {
                unsigned cnt = 0;
                while(cnt <= 16 && other.guid[cnt] < guid[cnt]) {
                        cnt ++;
                };
                if (cnt > 16) return true;
                return false;
        }

        bool operator==(const call_id &other) const
        {
                return !strncmp((const char *)guid[0], (const char *)other.guid[0], 16);
        }

        unsigned char guid[16];
};

typedef std::map<call_id, int> node_t;
typedef std::map<int, node_t > sess_t;

std::map< int, std::map<call_id, int> > sessions;
bool GetSession(int key, int &ptr, call_id guid)
{
        sess_t::iterator it = sessions.find(key);
        if (it == sessions.end()) {
                return false;
        };
        std::map<call_id, int> nodes_map = it->second;
        std::map<call_id, int>::iterator sess_it = std::find(nodes_map.begin(), nodes_map.end(), guid); // ЗДЕСЬ ОШИБКА
        if (sess_it != it->second.end()) {
                ptr = sess_it->second;
                return true;
        } else {
        }
        return false;
};


int main()
{
        int ptr;
        call_id guid;
        GetSession(20, ptr, guid);
        return 0;
}


Автор: mes 16.8.2013, 16:07
Цитата(Delen @  16.8.2013,  14:03 Найти цитируемый пост)
оператор == есть. Помогите найти ошибку.


он есть у call_id, а не у pair, которые вы перебираете в find..
Цитата(Delen @  16.8.2013,  14:03 Найти цитируемый пост)
std::pair<const call_id, int>&


std:find не подходит  для поиска по второму значению в мапе.. самый простой вариант перебрать мапу вручную..

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)