Re: strang function pointer from faq book (help)
From: Karl Heinz Buchegger (kbuchegg_at_gascad.at)
Date: Wed, 30 Mar 2005 10:36:22 +0200
> [my Q and your answer sniped...]
> > says:
> > FredMemberPt is an alias name for a data type. This data type is a
> > pointer to a member function of Fred, and it takes an int as
> > and returns void.
> But I don't find any member function called FredMemberpt in the class
> Fred.All my doubts starts there.Pls explain.
As said: The typedef defines a 'data type name'.
I don't know why you constantly search for a member function
called 'FredMemberPt' in Fred. The compiler doesn't spend a
millisecond to search for one, because the typedef does a completely
different thing: It defines a name for a specific data type. Nothing
more, nothing less.
The data type is: Pointer to member function in Fred, which takes an
int and returns void.
And the name given to that data type is: FredMemberPt
It is like a shortcut for you, the programmer. Such that you don't
have to constantly have to type that beast all over again, but can
use a shorter (and more readable name for it).
Your program has to work with arrays of 'long unsigned int' all over
the places. Eg.
long unsigned int a;
Now you get tired of typing this monster all the time. Thus you define
a typedef for it:
typedef long unsigned int UIntAr;
which makes UIntAr a second name for the data type 'long unsigned int '.
Then you can write:
That's what typedef does. While in the above array example it isn't such a good
idea, the typedef is a very good idea in the case of function pointers.
-- Karl Heinz Buchegger email@example.com