In your example, you are using a pointer vector: std::vector<A*> . Therefore, you need to define a comparison for the pointers you pass to std::lower_bound :
bool less_A_pointer (const A* lhs, const A* rhs) { return (lhs->key < rhs->key); } auto it = std::lower_bound(vec.begin(), vec.end(), element, less_A_pointer);
Of course, the question is why you use pointers in the first place - just store A objects if you really don't need to. If you need to save pointers, take a look at std::shared_ptr , which will handle this for you:
std::vector<std::shared_ptr<A>> v; std::shared_ptr<A> element(new A(...)); auto it = std::lower_bound(v.begin(), v.end(), element);
You can also use lambda instead of writing a free function:
auto it = std::lower_bound(v.begin(), v.end(), [](const A* lhs, const A* rhs) { return lhs->key < rhs->key; });
source share