Function pointer to member function of class

Submitted by:Jhon Brain

Date added:08 September, 2015

Category:C++

C++ code snippet for function pointer to member function of class

Tags: function pointer , member function

Code Snippet:

#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)();
}
 
 

Comments