passing pointer to member function that is const
Hi,
my problem is the following
let's say we have a class MyClass:
class MyClass {
int val;
bool check(int) const;
};
bool MyClass::check(int i) const {
return i==val;
}
and a global function f:
void f( bool (*g)(int) ) {
cout << (*g)(3) ;
now what I would like to be able to do is to pass MyClass::check to the function f.
simply doing
f(&MyClass::check);
is not working because the compiler complains it cannot convert 'bool (Myclass::*) (int)' to 'bool (*)(int)'
and I don't want to make the member function static because it has to access non static attributes. also I don't want my global function to be bound to any specific class (it should only take a function that accept a int and return a bool)
does anyone know how to solve this problem?
thanks
cla