#include <iostream>
#include <algorithm>
using namespace std;
struct arr
{
int a;int b;
}a[1000];
bool comp(arr &lhs, arr &rhs)
{ return lhs.a < rhs.a ; }
int main()
{
int n,i ;
sort(a,a+n,comp);
int ind= lower_bound(a,a+n,x,comp)-a;
return 0;
}
エラーメッセージ :
/usr/include/c++/4.9/bits/predefined_ops.h: 'bool __gnu_cxx::__ops::_Iter_comp_val<_Compare>::operator()(_Iterator, _Value&) のインスタンス化 [with _Iterator = arr*; _Value = const int; _Compare = bool ( )(arr&, arr&)]': /usr/include/c++/4.9/bits/stl_algobase.h:965:30:
'_ForwardIterator std::__lower_bound(_ForwardIterator, _ForwardIterator, const _Tp&, _Compare) から必要[ with _ForwardIterator = arr ; _Tp = 整数; _Compare = __gnu_cxx::__ops::_Iter_comp_val]' /usr/include/c++/4.9/bits/stl_algo.h:2036:46: '_FIter std::lower_bound(_FIter, _FIter, const _Tp&, _Compare) から必要 [with _FIter = arr*; _Tp = 整数; _Compare = ブール ()(arr&, arr&)]' prog.cpp:28:38: ここから必要 /usr/include/c++/4.9/bits/predefined_ops.h:141:37: エラー: タイプ 'arr&' の参照の初期化が無効です'const int' 型の式 { return bool(_M_comp( __it, __val)); } ^
構造体で lower_bound を使用して、 a[i].a に等しい値 x を検索したいですか? それに応じてコンパレータ関数を作成しましたが、何も作成できない長いエラーメッセージが表示されます。
関数を実行するために必要な変更。