Subscribe For Free Updates!

We'll not spam mate! We promise.

Apr 14, 2013

How do I declare, assign and call a pointer to a method?



How do I declare, assign and call a pointer to a method?

Note that a pointer to a method does not hold a second pointer to an instance of a
class. To use a pointer to a method, you need an instance of the class onto which this
method can be called (possibly a second pointer).

struct A
{
void m(int) {}
};
void function()
{
void (A::*pm)(int) = &A::m; // pointer on method
A a; // instance of a class
(a.*m)(1); // calling the method with parameter value 1.
}

TechniqZone Socializer Widget
SOCIALIZE IT →
FOLLOW US →
SHARE IT →

0 comments:

Post a Comment