0

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 ?

1
  • Misleading indentation. :) Commented Mar 26, 2016 at 14:07

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

How could i store copy of that , not by reference?
@user3706129 IDS tmp; tmp = *it; makes a copy of the IDS that it points to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.