pointer to a member function

A

Allan Bruce

How does one setup a pointer to a member function?
In C, I usually do:

void (*SetKey)(char); // declare a pointer to a function
SetKey = &gPrefs->SetUp; // set the pointer to a valid function
SetKey(lMsg.wParam); // call the function pointed to

but I get errors in cpp, how do I do this?
Thanks
Allan
 
D

Dave

void (*SetKey)(char); // declare a pointer to a function
SetKey = &gPrefs->SetUp; // set the pointer to a valid function
SetKey(lMsg.wParam); // call the function pointed to

but I get errors in cpp, how do I do this?
Thanks
Allan

class foo
{
public:
void func() {}
};

int main()
{
foo f;
void (foo::*ptr)() = &foo::func;
(f.*ptr)();
}
 

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
473,777
Messages
2,569,604
Members
45,222
Latest member
patricajohnson51

Latest Threads

Top