Given a vector
vector<classX *> myVec;
how to return the index i
of one of its elements as in the following function;
size_t nearestElement(classY const& p){
size_t i(0);
double d = distance(myVec[i]->position(), p);
for (auto const& element : myVec){
if(distance(element->position(), p) < d){
i = ???; // the index of the current element
}
return i;
}
}
where position()
is a function defined in classX
and distance
is not the std::distance
function, but a function I defined my self.