6
class A
{
   bool OutofRange(string& a, string& b, string c);
   void Get(vector <string>& str, string& a, string& b);
}

void A::Get(vector <string>& str, string& a, string& b)
{
   str.erase(
            std::remove_if (str.begin(), str.end(), BOOST_BIND(&A::OutOfRange, a, b, _1)),
            str.end()
            );
}

I am getting errors like:

 Error 7 error C2825: 'F': must be a class or namespace when followed by '::' File:bind.hpp
 Error 8 error C2039: 'result_type' : is not a member of '`global namespace'' t:\3rdparty\cpp\boost\boost-1.38.0\include\boost\bind.hpp 67 

Can someone tell me what I am doing wrong?

aajkaltak
  • 1,437
  • 4
  • 20
  • 28

1 Answers1

14

A::OutOfRange is a function of 4 arguments - implicit *this being the first argument, which is missing in your bind clause

catwalk
  • 6,340
  • 25
  • 16
  • i do not think I am missing any argument in the bind clause. I wrote my code based on this answer over here-- http://stackoverflow.com/questions/1677211/sort-using-boostbind/1677302#1677302 my code worked when those functions were not members of the class but when i made them members of the class, they did not work anymore! – aajkaltak Nov 11 '09 at 15:07
  • 3
    Listen to catwalk, he is right. You need something like this: BOOST_BIND(&A::OutOfRange, *this, a, b, _1) http://www.boost.org/doc/libs/1_40_0/libs/bind/bind.html#with_member_pointers – McBeth Nov 11 '09 at 15:21
  • 3
    @McBeth: in fact it is better: `boost::bind( &A::OutOfRange, this, a, b, _1 )`. Bind deals properly with pointers there, and on the other hand it makes copies of the arguments. In the case of passing a pointer the pointer is copied, if you pass a real object another object will be created and the copy will be used in the generated functor. – David Rodríguez - dribeas Nov 11 '09 at 15:34
  • @varun: Binding a pointer to a function and a pointer to a member function are quite different. Member functions have an implicit argument `Type * this` (or `Type const * this` in the case of const member functions) added by the compiler. When you want to bind a member function you need to provide what object you want the member method to be executed. That also differs from static functions in a class. – David Rodríguez - dribeas Nov 11 '09 at 15:36