读书人

bind错在那里了呢?该如何解决

发布时间: 2012-02-25 10:01:47 作者: rapoo

bind错在那里了呢?
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>


bool f(long x,long y ){ return x==y; }
using namespace std;
int main()
{
vector<long> a;
a.reserve(10);
a.push_back(10);
vector<long>::iterator it1=a.begin(),it2=a.end();
if( (it1=find(it1,it2,
bind2nd(ptr_fun(f),10)))
==it2 )
{
cout<<"find 10:"<<endl;
cout<<*it1<<endl;
}


}
:\program files\microsoft visual studio 8\vc\include\algorithm(40) : error C2784: “bool std::operator ==(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)”: 无法从“long”为“const std::vector<_Ty,_Alloc> &”推导 模板 参数
c:\program files\microsoft visual studio 8\vc\include\vector(1259) : 参见“std::operator ==”的声明
c:\program files\microsoft visual studio 8\vc\include\algorithm(74): 参见对正在编译的函数 模板 实例化“_InIt std::_Find<std::_Vector_iterator<_Ty,_Alloc>,std::binder2nd<_Fn2>>(_InIt,_InIt,const std::binder2nd<_Fn2> &)”的引用
with
[
_InIt=std::_Vector_iterator<long,std::allocator<long>>,
_Ty=long,
_Alloc=std::allocator<long>,
_Fn2=std::pointer_to_binary_function<long,long,bool,bool (__cdecl *)(long,long)>
]
e:\c++分支\ddddddddddddddddddddd\ddddddddddddddddddddd\ffffff.cpp(19): 参见对正在编译的函数 模板 实例化“_InIt std::find<std::_Vector_iterator<_Ty,_Alloc>,std::binder2nd<_Fn2>>(_InIt,_InIt,const std::binder2nd<_Fn2> &)”的引用
with
[
_InIt=std::_Vector_iterator<long,std::allocator<long>>,
_Ty=long,
_Alloc=std::allocator<long>,
_Fn2=std::pointer_to_binary_function<long,long,bool,bool (__cdecl *)(long,long)>
]
c:\program files\microsoft visual studio 8\vc\include\algorithm(40) : error C2784: “bool std::operator ==(const std::istream_iterator<_Ty,_Elem,_Traits,_Diff> &,const std::istream_iterator<_Ty,_Elem,_Traits,_Diff> &)”: 无法从“long”为“const std::istream_iterator<_Ty,_Elem,_Traits,_Diff> &”推导 模板 参数
c:\program files\microsoft visual studio 8\vc\include\iterator(266) : 参见“std::operator ==”的声明
c:\program files\microsoft visual studio 8\vc\include\algorithm(40) : error C2784: “bool std::operator ==(const std::allocator<_Ty> &,const std::allocator<_Other> &) throw()”: 无法从“long”为“const std::allocator<_Ty> &”推导 模板 参数
c:\program files\microsoft visual studio 8\vc\include\xmemory(174) : 参见“std::operator ==”的声明
c:\program files\microsoft visual studio 8\vc\include\algorithm(40) : error C2784: “bool std::operator ==(const std::istreambuf_iterator<_Elem,_Traits> &,const std::istreambuf_iterator<_Elem,_Traits> &)”: 无法从“long”为“const std::istreambuf_iterator<_Elem,_Traits> &”推导 模板 参数
c:\program files\microsoft visual studio 8\vc\include\xutility(2143) : 参见“std::operator ==”的声明
c:\program files\microsoft visual studio 8\vc\include\algorithm(40) : error C2784: “bool std::operator ==(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)”: 无法从“long”为“const std::reverse_iterator<_RanIt> &”推导 模板 参数
c:\program files\microsoft visual studio 8\vc\include\xutility(1826) : 参见“std::operator ==”的声明
c:\program files\microsoft visual studio 8\vc\include\algorithm(40) : error C2784: “bool std::operator ==(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)”: 无法从“long”为“const std::pair<_Ty1,_Ty2> &”推导 模板 参数


c:\program files\microsoft visual studio 8\vc\include\utility(60) : 参见“std::operator ==”的声明
c:\program files\microsoft visual studio 8\vc\include\algorithm(40) : error C2677: 二进制“==”: 没有找到接受“const std::binder2nd<_Fn2>”类型的全局运算符(或没有可接受的转换)
with
[
_Fn2=std::pointer_to_binary_function<long,long,bool,bool (__cdecl *)(long,long)>
]
生成日志保存在“file://e:\C++分支\ddddddddddddddddddddd\ddddddddddddddddddddd\Debug\BuildLog.htm”
ddddddddddddddddddddd - 7 个错误,0 个警告

求改正!

[解决办法]
find函数改为find_if
[解决办法]

C/C++ code
template<class _II, class _Ty> inline    _II find(_II _F, _II _L, const _Ty& _V)//这里面传入的第三个参数是一个值    {for (; _F != _L; ++_F)        if (*_F == _V)            break;    return (_F); }        // TEMPLATE FUNCTION find_iftemplate<class _II, class _Pr> inline    _II find_if(_II _F, _II _L, _Pr _P)//这里面传入的第三个参数是一个函数对象    {for (; _F != _L; ++_F)        if (_P(*_F))            break;    return (_F); } 

读书人网 >C++

热点推荐