c++ - Finding a pointer in a list -


i'd find element in list containing pointers.

this question quite similar find item in list of pointers, tried in different way , seems working.

in linked question people suggested using find_if, lambdas , thing this. isn't enough pass sought pointer std::find? miss out something?

here's code used testing, , seems working. run different parameters , got expected results.

typedef struct _c {      int num;      int name; } c;  int main(void) {     c *new_c = new c();     new_c->num = 2;     new_c->name = 1;      c *new_b = new c();     new_b->num = 3;     new_b->name = 32;      c *new_d = new c();     new_d->num = 1;     new_d->num = 11;      std::list<c *> list;     list.push_front(new_b);     list.push_front(new_c);      std::list<c *>::iterator del_new =         std::find(list.begin(), list.end(), new_c);      if(del_new != list.end())         std::cout << "found" << std::endl;     else         std::cout << "not found" << std::endl; 

you code correct . looking pointer same looking integer type, std::find list way pointer (time complexity o(n)).


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -