EECS 280 Lecture 18: Iterators

58 views3 pages

Document Summary

Will work a lot like using a pointer to traverse an array. Forward_list ; for (forward_list::iterator i = fl. begin(); i != fl. end(); ++i){ cout << *i << endl; Operator overloading lets us customize what happens when we use a built-in symbol. //we could template the iterator so that it returns the exact same t that"s inside the list. I mention this because it needs to have access to private member variables that are inside of list. We could also solve this problem by declaring iterator inside of list class iterator { Iterator& operator++(); bool operator!= (iterator res) const // compare. Node *node_ptr will point to one node on the list or none at all. Implementing one of the overloads: int & operator* () const { assert(node_ptr); //makes sure that it"s not null return node_ptr->datum; // the compiler automatically knows to.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents

Related Questions