typedef syntax with member function pointers

muxmux picture muxmux · Jun 7, 2011 · Viewed 38.2k times · Source

according to MSDN the typedef syntax is:

typedef type-declaration synonym;

Very easy:

typedef int MY_INT;

But how the heck does the member-function-pointer typedefs comply to this rule?

typedef int (MyClass::*MyTypedef)( int);

100% confusion – the synonym (MyTypedef) is in the middle?

Can someone please explain what the logical steps are to get from the very easy to understand syntax format of MSDN to the reverse/random/front/last/mixed syntax thing of aboves typedef?

*edit thanks for all the fast answers (and the beautification of my post) :)

Answer

Nawaz picture Nawaz · Jun 7, 2011

the synonym (MyTypedef) is in the middle??

Its not in the middle. Just forget member-function for a while, see how a function pointer is defined:

int (*FuncPtr)(int);

And this is how you would typedef it:

typedef int (*FuncPtr)(int); 

Simple! The only difference is, in the typedef FuncPtr becomes a type, while in the pointer declaration, FuncPtr is a variable.

Similarly,

int (MyClass::*MyTypedef)( int); //MyTypedef is a variable

And the typedef as:

typedef int (MyClass::*MyTypedef)( int); //MyTypedef is a type!