Passing this as default argument

M

Martin Magnusson

I'm writing a custom iterator which works on a specific class and needs
access to some of this class' private data. The iterator class is a
friend of the other class, but I suppose that the iterator also needs a
pointer to the object over which it iterates.

My question is: what's the easiest way to supply this pointer? It seems
slightly cumbersome to have to do something like
Vertex_Iterator i( this );
everytime I create a new Vertex_Iterator.

Is there a better way?

/ martin
 
L

lilburne

Martin said:
I'm writing a custom iterator which works on a specific class and needs
access to some of this class' private data. The iterator class is a
friend of the other class, but I suppose that the iterator also needs a
pointer to the object over which it iterates.

My question is: what's the easiest way to supply this pointer? It seems
slightly cumbersome to have to do something like
Vertex_Iterator i( this );
everytime I create a new Vertex_Iterator.

Is there a better way?

IMO No!

Realistically how many places in the class need to create an iterator
over itself? How many places outside of the class need to create an
iterator? A default is only usefull if the vast majority of the time
(99.9999%) the default is what you want. IOW not using the default is
exceptional.

Why can't you create a function on the class that returns an iterator
over itself?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,175
Messages
2,570,942
Members
47,490
Latest member
Finplus

Latest Threads

Top