Richard Robertson Posted April 22, 2009 Share Posted April 22, 2009 How does one implement a reference without an address of some flavor? Link to comment Share on other sites More sharing options...
Valik Posted April 22, 2009 Share Posted April 22, 2009 How does one implement a reference without an address of some flavor?Iterators can be thought of as reference and pointer hybrids. Iterators exist to provide pseudo-references to objects while still retaining the ability to iterator like a pointer. When looking at an iterator as a reference we see what we expect which is the iterator is capable of acting like the source object. It's possible to read from and assign to the source object an iterator is currently referencing. So, if we look at an iterator class as a glorified reference implementation we can see alternate ways to access references. Imagine a simple vector iterator. All the iterator needs to store is an index. The vector itself stores the data in some fashion (a linear array most likely). The iterator stores an index into that array. When access to the object through the iterator is required, the iterator indexes into the vector's array. It is an implementation detail outside the iterator (reference's) concern that index into a linear array happens to be done via address offsets. The iterator (reference) itself knows nothing about addresses in this scenario. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now