Kiran's Blog

Ramblings from a dehydrated mind…

  • Archives

    • 14,897

Pointer to member functions

Posted by kiraninbng on July 10, 2006


A pointer to a member function consists of return type, the class name followed by ::, the function pointer name and the
function’s parameter list.

Ex :

class CTest
{
 int fn();
}

// pmCTest is a pointer to a member function which takes int as the parameter
int CTest::*pmCTest();
Below code shows how to invoke the pointer to member function,

pmCTest = &CTest::fn;
CTest oCTest;
CTest *pCTest = &oCTest;
// Invoke the member function using an object
(oCTest.*pmCTest)();
// Invoke the member function using an object pointer
(pCTest->*pmCTest)();

If you call virtual member function using a pointer to member function, the call will get resolved dynamically.

Also the size of the pointer to member function can change depending on whether the class is inherited from a single class
or from multiple classes.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: