-
Re: Problem: Pass a Class Member Function as an argument to another
You can pass a pointer to a member, but in order to call the member
function through it, you will also need to pass a reference to an
object:
class A
{
public:
void f();
};
int func(A& r, void (A::*pmf)())
{
(r.*pmf)(); // call member function through ptr
}
int main()
{
A a;
void (A::*p)() = &A::f; //take member's address
func(&a, p);
}
Danny Kalev
"The ANSI/ISO C++ Professional Programmer's Handbook"
http://www.amazon.com/exec/obidos/ASIN/0789720221
"Helder Simões" wrote:
>
> Hi,
>
> I have a problem: is it possible to pass a class member function as an argument
> to another function?
>
> I know it is possible with normal functions, but I couldn't figure it out
> with class members.
>
> Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|