c++ - Compile error in std::find_if -


this question has answer here:

can explain doing wrong here?

class base_type { public:          string name;         int localtype; };  boost::ptr_vector<base_type> tvector;   struct findvariable {     findvariable(const string& name) : _name(name) {};     const string& _name;      bool operator () (const base_type& arg) const     {         return (_name == arg.name);     } };  typedef boost::ptr_vector<base_type>::iterator tvector_it;   inline tvector_it findvariable(string& _name)  {     return find_if(tvector.begin(), tvector.end(), findvariable(_name));         } 

compile error:

...\vc\include\algorithm(43): error c2064: term not evaluate function taking 1 arguments

...\vc\include\algorithm(54): note: see reference function template instantiation '_init std::_find_if<_iter,_pr>(_init,_init,_pr)' being compiled [ _init=boost::void_ptr_iterator>>,var_t::base_type>, _iter=boost::void_ptr_iterator>>,var_t::base_type>, _pr=var_t::tvector_it ]

you have structure named findvariable, have function named findvariable.

in function, when findvariable(_name) don't create instance of structure, call function recursively. , function not return can use predicate std::find_if compiler gives error.

simple solution? rename structure, or function.


Comments