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

pointer to a member function

P: n/a
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


Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"Allan Bruce" <al*****@TAKEAWAYf2s.com> wrote in message
news:bq**********@news.freedom2surf.net...
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?


RTFF.

http://www.parashift.com/c++-faq-lit...o-members.html

-Mike
Jul 22 '05 #2

P: n/a
> 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)();
}
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.