Function pointer to member function of class source code

This snippet submitted by selvam on 2011-11-28. It has been viewed 11804 times.
Rating of 5.1 with 75 votes

#include <iostream>

using namespace std;

class A
{
public:
void func()
{
cout << "Inside func of class A" << endl;
}
};

int main()
{
  //function pointer declaration
  void (A::*fp)(); //return type,(class::function pointer)(arguments)
  fp = &A::func;//assigning
  A *a = new A;
  (a->*fp)();
} 




More C and C++ source code snippets