[lug] Passing member functions around
Chris Riddoch
socket at peakpeak.com
Wed Oct 18 07:39:00 MDT 2000
I realize there are probably better forums for this, but I know a
number of people on the BLUG use C++ on a regular basis, and I hope
someone can help me out.
The question: what's the syntax for passing a member function to
another member function? My project is vaguely like the example
below, but has about half a dozen functions that will need to be
passed to the iterator from about twelve others, and it's all
implemented over a linked list, so the iterator is actually useful in
my real program.
Compilation breaks on the call to iterator() in do_body() because I
can't figure out the syntax for sending body() to iterator().
Thanks.
--
Chris Riddoch
socket at peakpeak.com
----
#include <iostream>
int times=20;
class thing {
public:
int body(int number)
{ cout << number << endl; return 0; }
void iterator(int times, int (*inner)(int number))
{
for (int i = 0; i < times; i++)
inner(i);
}
void do_body()
{
iterator(10, body); // How do I pass 'body' to iterator?
}
};
int main()
{
thing a;
a.do_body();
}
More information about the LUG
mailing list