Thursday, August 16, 2012


The predicate cannot be declared inside the function.
 The following works, move I declaration into main, and the compiler outputs


remif.cpp:19:19: error: no matching function for call to ‘std::list<int>::remove_if(main()::I)’
remif.cpp:19:19: note: candidate is:
/usr/include/c++/4.6/bits/stl_list.h:1330:9: note: template<class _Predicate> void std::list::remove_if(_Predicate) [with _Predicate = _Predicate, _Tp = int, _Alloc = std::allocator<int>]
make: *** [remif] Error 1


struct I{
  int a;
  bool operator()(const int& x){
    return x==a;
  I(int ap):a(ap){}

int main(){
  std::list<int> x;



No comments:

Post a Comment