I have a vector of structs eg
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 ?
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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.