#include<functional>
#include<list>
class A {
public: virtual bool isOdd(int x) = 0;
};
class B : public A {
public: bool isOdd(int x) override
{ return (x%2)!=0; }
};
int main () {
A *a = new B();
std::list<int> l {1,2,3,4};
l.remove_if(a->isOdd);
return 0;
}
This code produces the following compiler error for l.remove_if(a->isOdd);:
reference to non-static member function must be called
How can I call remove_if so that the isOdd implementation of class B is called?
I'm not looking for a solution that directly references B::isOdd. Instead, I want to have a pointer to the abstract class A and multiple (non-abstract) subclasses of A and use the implementation of whatever derived class the pointer points to.