I want to find in a vector of Object pointers for a matching object. Here\'s a sample code to illustrate my problem:
class A {
public:
A(string a):_a(a) {}
Use find_if with a functor:
template
struct pointer_values_equal
{
const T* to_find;
bool operator()(const T* other) const
{
return *to_find == *other;
}
};
// usage:
void test(const vector& va)
{
A* to_find = new A("two");
pointer_values_equal eq = { to_find };
find_if(va.begin(), va.end(), eq);
// don't forget to delete A!
}
Note: your operator== for A ought to be const, or, better still, write it as a non-member friend function.