Jump to content

Pointer Question


CoolPenguin
 Share

Recommended Posts

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...