Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/157.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ bind()用于将成员函数用作STL比较函数_C++_Stl_Comparison_Bind - Fatal编程技术网

C++ bind()用于将成员函数用作STL比较函数

C++ bind()用于将成员函数用作STL比较函数,c++,stl,comparison,bind,C++,Stl,Comparison,Bind,有人能告诉我为什么下面的内容无法编译吗 #include "a.h" #include <list> #include <algorithm> #include <tr1/functional> using namespace std; class B { public: B() { list< A* > aList; A* a = new A(); lower_bound( aList.begi

有人能告诉我为什么下面的内容无法编译吗

#include "a.h"
#include <list>
#include <algorithm>
#include <tr1/functional>

using namespace std;

class B {
  public:
    B() {
      list< A* > aList;
      A* a = new A();
      lower_bound( aList.begin(), aList.end(), a, tr1::bind( &B::aComp, tr1::placeholders::_1, tr1::placeholders::_2 ) );
    }
  private:
    bool aComp( A* a1, A* a2 );
};
#包括“a.h”
#包括
#包括
#包括
使用名称空间std;
B类{
公众:
B(){
列表列表;
A*A=新的A();
下限(aList.begin(),aList.end(),a,tr1::bind(&B::aComp,tr1::占位符::_1,tr1::占位符::_2));
}
私人:
bool-aComp(A*a1,A*a2);
};
编译输出:

In file included from c:\qt\2010.04\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/tr1/functional:56, 
from ..\bindTest\/b.h:4, 
from ..\bindTest\b.cpp:1: 
c:\qt\2010.04\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/tr1_impl/functional: In member function 'typename std::tr1::result_of<_Functor(typename std::tr1::result_of<std::tr1::_Mu<_Bound_args, std::tr1::is_bind_expression::value, (std::tr1::is_placeholder::value > 0)>(_Bound_args, std::tr1::tuple<_UElements ...>)>::type ...)>::type std::tr1::_Bind<_Functor(_Bound_args ...)>::__call(const std::tr1::tuple<_UElements ...>&, std::tr1::_Index_tuple<_Indexes ...>) [with _Args = A*&, A* const&, int ..._Indexes = 0, 1, _Functor = std::tr1::_Mem_fn<bool (B::*)(A*, A*)>, _Bound_args = std::tr1::_Placeholder<1>, std::tr1::_Placeholder<2>]': 
c:\qt\2010.04\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/tr1_impl/functional:1191: instantiated from 'typename std::tr1::result_of<_Functor(typename std::tr1::result_of<std::tr1::_Mu<_Bound_args, std::tr1::is_bind_expression::value, (std::tr1::is_placeholder::value > 0)>(_Bound_args, std::tr1::tuple<_UElements ...>)>::type ...)>::type std::tr1::_Bind<_Functor(_Bound_args ...)>::operator()(_Args& ...) [with _Args = A*, A* const, _Functor = std::tr1::_Mem_fn<bool (B::*)(A*, A*)>, _Bound_args = std::tr1::_Placeholder<1>, std::tr1::_Placeholder<2>]' 
c:\qt\2010.04\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/bits/stl_algo.h:2495: instantiated from '_FIter std::lower_bound(_FIter, _FIter, const _Tp&, _Compare) [with _FIter = std::_List_iterator<A*>, _Tp = A*, _Compare = std::tr1::_Bind<std::tr1::_Mem_fn<bool (B::*)(A*, A*)>(std::tr1::_Placeholder<1>, std::tr1::_Placeholder<2>)>]' 
..\bindTest\/b.h:13: instantiated from here 
c:\qt\2010.04\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/tr1_impl/functional:1137: error: no match for call to '(std::tr1::_Mem_fn<bool (B::*)(A*, A*)>) (A*&, A* const&)' 
c:\qt\2010.04\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/tr1_impl/functional:546: note: candidates are: _Res std::tr1::_Mem_fn<_Res (_Class::*)(_ArgTypes ...)>::operator()(_Class&, _ArgTypes ...) const [with _Res = bool, _Class = B, _ArgTypes = A*, A*] 
c:\qt\2010.04\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/tr1_impl/functional:551: note: _Res std::tr1::_Mem_fn<_Res (_Class::*)(_ArgTypes ...)>::operator()(_Class*, _ArgTypes ...) const [with _Res = bool, _Class = B, _ArgTypes = A*, A*] 
在c:\qt\2010.04\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/tr1/functional:56中包含的文件中,
from..\bindTest\/b.h:4,
from..\bindTest\b.cpp:1:
c:\qt\2010.04\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/tr1\u impl/functional:In成员函数“typename std::tr1::result\u of::type…”>:type std::tr1::\u调用(const std::tr1::tuple&,std::tr1:\u Index\tuple)[with _Args=A*&,A*const&,int…_index=0,1,_Functor=std::tr1::_Mem\u fn,_Bound_Args=std::tr1::_占位符,std::tr1::_占位符]:
c:\qt\2010.04\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/tr1_impl/functional:1191:从“typename std::tr1::result of::type…”实例化:type std::tr1::_Bind::operator()(_Args&…)[带有_Args=A*,A*const,_Functor=std::tr1::_memfn,_boundargs=std::tr1:::(占位符,std::tr1:)
c:\qt\2010.04\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/bits/stl_-algo.h:2495:从“_-FIter-std::lower_-bound(_-FIter,_-FIter,const _-Tp&,_-Compare)[with _-FIter=std:_-List\u迭代器,_-Tp=A*,_-Compare=std::tr1:_-Bind]实例化”
..\bindTest\/b.h:13:从此处实例化
c:\qt\2010.04\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/tr1_impl/functional:1137:错误:调用(std::tr1::_Mem_fn)(A*&,A*常量&)不匹配
c:\qt\2010.04\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/tr1\u impl/functional:546:注:候选项为:_resstd::tr1::_Mem\u fn::operator()(_Class&,_ArgTypes…)const[带_Res=bool,_Class=B,_ArgTypes=A*]
c:\qt\2010.04\mingw\bin\../lib/gcc/mingw32/4.4.0/include/c++/tr1_impl/functional:551:注意:_resstd::tr1::_Mem_fn::operator()(_Class*,_ArgTypes…)const[带_Res=bool,_Class=B,_ArgTypes=A*]

aComp
B
的非静态成员函数,因此您还需要绑定到
这个
指针:

tr1::bind(&B::aComp, this, tr1::placeholders::_1, tr1::placeholders::_2)

aComp
B
的一个非静态成员函数,因此您还需要绑定到
这个
指针:

tr1::bind(&B::aComp, this, tr1::placeholders::_1, tr1::placeholders::_2)
有史以来最长的错误线。oO@ereOn:不幸的是,错误--这只是一个页面长度。我已经生成了一个超过四个页面长度的模板(包括一个模板实例化,当您展开所有模板参数时,其类型的名称超过了一个页面长度).有史以来最长的错误行。oO@ereOn:不幸的是,错误--这只是一页长。我已经生成了一个超过四页长的模板(包括一个模板实例化,当您展开所有模板参数时,其类型的名称超过了一页长)。