Answers for "get index by pointer to element of vector c++"

C++
0

get index by pointer to element of vector c++

std::vector<MyObject> vect;
MyObject *ptrX = ... // Pointer to element
ptrdiff_t index = ptrX - &vect[0];
Posted by: Guest on April-23-2021

Code answers related to "get index by pointer to element of vector c++"

Browse Popular Code Answers by Language