/*Orion Lawlor's Simple C++ Examples, olawlor@acm.org
Shows how to use pointer-to-member functions.
*/
#include <iostream>

class foo {
public:
	void A(int x) {std::cout<<"A("<<x<<")"<<std::endl;}
	void B(int x) {std::cout<<"B("<<x<<")"<<std::endl;}
};

//Declares a type named "foo_fn_t"
typedef void (foo::* foo_fn_t) (int x);

int main()
{
	foo f;
	foo_fn_t func=&foo::A;
	
	//Call member function pointer func on f (direct)
	(f.* func)(3);
	
	func=&foo::B;
	foo *pf=&f;
	
	//Call on pf (via pointer)
	(pf->* func)(7);
	
	return 0;
}

/*<@>
<@> ******** Program output: ********
<@> A(3)
<@> B(7)
<@> */
