Define predicate within class
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.
No comments:
Post a Comment