I have a class A
with a member which is a vector of object pointers of another class B
class A
{
std::vector<B*> m_member_A
Now I want to perform a std::find
on m_member_A
.
E.g.
if(std::find(m_member_A.begin(), m_member_A.end(), B_obj*) != m_member_A.end())
std::find doesn't make sense on such a vector. How do I achieve such a functionality?
How would it change if it were a vector of objects of B (not pointer)?
If you want to find a value pointer at by the pointer, instead of a given pointer, you can use
std::find_if
with a suitable functor:Vector works perfectly fine with
std::find
Or if you need to dereference the pointer:
Demo: http://ideone.com/jKCrG5
If you want to compare values instead of comparing pointers, you might want to use std::find_if instead: