How to use find algorithm with a vector of pointers to objects in c++?

后端 未结 4 2155
逝去的感伤
逝去的感伤 2021-02-07 07:04

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) {}
          


        
4条回答
  •  佛祖请我去吃肉
    2021-02-07 07:45

    You could also use Boost::Lambda:

    using namespace boost::lambda;
    find_if(va.begin(), va.end(), *_1 == A("two"));
    

    Of course, you should prefer to use shared_ptrs so you don't have to remember to delete!

提交回复
热议问题