By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,778 Members | 1,890 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,778 IT Pros & Developers. It's quick & easy.

Passing this as default argument

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a


Martin Magnusson wrote:
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?

Jul 22 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.