c++ - Polymorphism,STL,find and operator== -
i ran problem. have class a,and class inherits a,lets call class b. have virtual functions. want compare , b class c operator==. if want have list of a's,lets in stl list, must use pointer a,so like:
list<*a> list; and have: c something
but now,i cant use function:find(list.begin(),list.end(),something) because cant use operator == pointers(*).
i found solution dont think best,so question is-can better?
iter=list.begin(); for(iter;iter!=list.end();++iter) { if((*iter).operator==(something) return ... } thank you.
you use find_if, lets provide function check equal values.
auto check_something = [&something](const list<*a>::iterator& iter){return *iter == something; }; find_if(list.begin(),list.end(),check_something)
Comments
Post a Comment