tags:

views:

47

answers:

1

why won't this work when i use template function predicate.

class A
{
    int x;
public:
    A(int X):x(X){}
    int getX() const {return x;}
};

template <typename T>
bool less_than_two(T const &a)
{
    return (a.getX()<2);
}

int main()
{
    list <A> l;

    for (int i = 0; i < 5; i++)
        l.push_back(i);

    l.remove_if(less_than_two);
}
+5  A: 

You need to instantiate the template with type A. So you need to do l.remove_if(less_than_two<A>);

Naveen