Code:
class Checkable {
public:
bool check(int i) const=0;
};
Make the function virtual. Any class that you want to be able to check should implement the Checkable interface. Then, change the signature of f to something like this
void f(Checkable* g);
Here, while you can do this with any class you write (just make it support Checkable interface), you can't pass functions to it.
Alternatively, you could use templates
Code:
#include <iostream>
bool retFalseFunc(int i) {
return false;
}
class EqualityFunctor {
int privInt;
public:
bool operator()(int i) const {
return i == privInt;
}
EqualityFunctor(int i) : privInt(i) { }
};
template <typename func> void f(func g) {
std::cout << "function like thing g returns " << g(2) << " when passed a 2 " << std::endl;
}
int main() {
f(retFalseFunc);
f(EqualityFunctor(3));
f(EqualityFunctor(2));
return 0;
}