next up previous
Next: How can I handle Up: class and struct Previous: How do I put

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.

Alexis Angelidis (PhD) 2005-01-11