Function pointer to member function of class

Submitted by:Pitter Alderson

Date added:11 May, 2015

Category:C++

Example source code 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