Надеюсь, это не до боли очевидно.Я получаю эту зашифрованную ошибку:
fold.cpp:92: error: expected primary-expression before ‘)’ token
Строка, на которую она ссылается:
if (binary_search (corpus.begin(),corpus.end(), left, customArray::operator<(customArray)))
Я пришел к этой ошибке после использования более простого вызова:
if (binary_search (corpus.begin(),corpus.end(), left))
и получение этого сообщения об ошибке (важной частью является примечание в конце, в котором говорится, что нужно заменить его на вышеуказанный вызов)
In function ‘bool std::binary_search(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = std::_List_iterator<customArray>, _Tp = std::string [3]]’:
fold.cpp:92: instantiated from here
/usr/include/c++/4.2.1/bits/stl_algo.h:4240: error: no match for ‘operator<’ in ‘__val < __i. std::_List_iterator<_Tp>::operator* [with _Tp = customArray]()’
/usr/include/c++/4.2.1/bits/stl_algo.h: In function ‘_ForwardIterator std::lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = std::_List_iterator<customArray>, _Tp = std::string [3]]’:
/usr/include/c++/4.2.1/bits/stl_algo.h:4239: instantiated from ‘bool std::binary_search(_ForwardIterator, _ForwardIterator, const _Tp&) [with _ForwardIterator = std::_List_iterator<customArray>, _Tp = std::string [3]]’
fold.cpp:92: instantiated from here
/usr/include/c++/4.2.1/bits/stl_algo.h:2906: error: no match for ‘operator<’ in ‘__middle. std::_List_iterator<_Tp>::operator* [with _Tp = customArray]() < __val’
fold.cpp:16: note: candidates are: bool customArray::operator<(customArray)
По сути, я пытаюсь использовать двоичный поиск длясвязанный список пользовательских (тип массива) объектов.Остальная часть соответствующего кода находится здесь:
// here is the custom class I am using in the list
class customArray
{
public:
// this is a somewhat lame way to compare, but it seems to work
bool operator< (customArray temp)
{
return array[0] < temp.array[0];
}
bool operator> (customArray temp)
{
return array[0] > temp.array[0];
}
bool operator== (customArray temp)
{
return ((array[0] == temp.array[0]) && (array[1] == temp.array[1]) && (array[2] == temp.array[2]));
}
string array[3];
};
//All of this stuff is in main
customArray one;
//some processing here to fill one
corpus.push_back (one);
// sort the list
corpus.sort();
corpus.unique();
string left [3];
if (binary_search (corpus.begin(),corpus.end(), left, customArray::operator<(customArray)))
{
}
Надеюсь, это легко понять.Дайте мне знать, если есть какой-либо способ, которым я могу уточнить.