[lug] Passing member functions around
Chris Riddoch
socket at peakpeak.com
Wed Oct 18 12:09:53 MDT 2000
"King, Kevin" <KKing at ftenergy.com> writes:
> To pass a member function pointer, use this syntax:
>
> void iterator(int times, int (thing::*inner)(int number))
>
> The problem is, it's not useful in that context. If the function weren't a
> member function then it would make some sense, but as a member function
> you're passing a pointer to a function which doesn't inherently know about
> the object that it's affecting.
>
> See http://marshall-cline.home.att.net/cpp-faq-lite/pointers-to-members.html
> for more info.
>
> --Kevin
> Kevin at PrecisOnline.com
> http://www.PrecisOnline.com
> http://www.PrecisOnline.com/gold.htm
Hm. Maybe, but the alternative seems to be to have code that iterates
through a linked list in an awful lot of separate functions in the
class, given my interface requirements. I'm trying to reduce the
number of places where I have to do similar things, and I decided that
an iterator shouldn't necessarily need to know anything about the
function it's being told to run except whether to break out of the
loop.
I wouldn't need the iterator inside the class, except that the list is
self-contained in the class as well.
--
Chris Riddoch
socket at peakpeak.com
More information about the LUG
mailing list