I have a class with a method which I would also like to be able to use as a predicate.
class MyClass {
bool ParticleHasAncestor(const Particle &particle, int id) const;
class AncestorPredicate {
int mId;
public:
AncestorPredicate(int idCode) : mId(idCode) { }
bool operator()(const Particle &particle) const { return ParticleHasAncestor(particle, mId); }
};
};
However, the compiler complains about not being able to use ParticleHasAncestor() without an instance of MyClass. Do I need to use a friend class? Or is there a better solution to this?
I am not using C++11, so cannot use lambda functions.
Update: ParticleHasAncestor() cannot be made static since it uses members of MyClass.
Make this predicate a static method. But it cannot be const then.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With