これは痛いほど明白ではないことを願っています。アルゴリズム:: binary_searchコールで期待されるプライマリ式の呼び出し
fold.cpp:92: error: expected primary-expression before ‘)’ token
それが参照している行は次のとおりです:
if (binary_search (corpus.begin(),corpus.end(), left))
となって:
if (binary_search (corpus.begin(),corpus.end(), left, customArray::operator<(customArray)))
は、私はシンプルな呼び出しを使用した後、このエラーに到着した私は、この不可解なエラーを取得していますこのエラーメッセージ(重要な部分は最後の注記で、上記の呼び出しに変更すると言っています)
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)
本質的に、カスタム(配列タイプ)オブジェクトのリンクリストでバイナリ検索を使用しようとしています。 relaventコードの残りの部分は次のとおりです。
// 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)))
{
}
これはわかりやすいものです。私が明確にできる方法があれば教えてください。
ああ、これは私が実現したよりも大きな問題です。私はベクトルの使用に切り替える必要がありますね。どうもありがとうございました!私はこれを受け入れるとすぐにこの答を受け入れます。 –