[lug] (OT) C++ ?, pointers to member functions
Scott A. Herod
herod at interact-tv.com
Tue Aug 7 15:25:18 MDT 2001
This is off topic but there are a lot of experts here.
How can I pass a pointer to a non-static member function?
I've got a static sample below but really want b::fp to be
non-static. Must I use a static, have it reference a non-static
and pass around a 'this' pointer?
Thanks,
Scott
==============================================================
#include <iostream>
typedef void (fpLOCK_WRITE)();
class f_ptr
{
public:
f_ptr( fpLOCK_WRITE* t ) { writer = t; }
void write() { writer(); }
private:
fpLOCK_WRITE* writer;
};
class b {
public:
static void fp() { cout << "Hello World!" << endl; }
};
int main( int argc, char* argv[] )
{
b* bp = new b();
f_ptr* f = new f_ptr( b::fp );
f->write();
return( 0 );
}
More information about the LUG
mailing list