Reputation: 229
I have a vector of structs e.g
struct IDS{
string name;
int age;
IDS(string name, int age){
this->name = name;
this ->age = age;
}
}
vector<IDS> myVector;
I am filling this vector with structs , and later on i want find a struct with specific value and save pointer to it. I tried using
IDS *tmp;
auto it = find_if (temp->myVector.begin(), temp->myVector.end(), [&](const IDS &y) {
return y.age == age;
});
if ( it != temp -> myVector.begin() ){
tmp =it
}
the vector is inside a linked list. This throws this error
cannot convert '__gnu_cxx::__normal_iterator
' to 'IDS*' in assignment|
How can i fix this error , and how can i store iterator pointer ?
Upvotes: 0
Views: 69
Reputation: 9991
it
is an iterator, not a pointer. You can use tmp = &(*it);
to convert the iterator to a pointer.
Alternatively you could make tmp
a std::vector<IDS>::iterator
.
Upvotes: 4