Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

typedef syntax with member function pointers

Tags:

c++

typedef

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) :)

like image 776
muxmux Avatar asked Jun 07 '11 13:06

muxmux


1 Answers

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! 
like image 131
Nawaz Avatar answered Sep 28 '22 03:09

Nawaz