Function pointer to member function of class source code

This snippet submitted by selvam on 2011-11-28. It has been viewed 5283 times.
Rating of 4.0 with 39 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

Add a snippet!