I am having trouble dereferencing a found shared_ptr
from a vector
after std::find
. Could someone explain why this is the case?
extern std::vector< shared_ptr<King::Actor> > selected
foo(const std::vector<std::shared_ptr<Actor>> &playerUnits)
{
std::vector<std::shared_ptr<Actor>>::const_iterator result;
result = std::find(std::begin(playerUnits), std::end(playerUnits), selected.back());
if (result != std::end(playerUnits))
return *std::next(result); // found
return nullptr;
}
enter code here
closest answer is https://stackoverflow.com/questions/301959/vector-iterator-not-dereferencable#= I believe it both found it and not the end of the vector, yet it still reports not dereferencable.