Re: strang function pointer from faq book (help)
From: Karl Heinz Buchegger (kbuchegg_at_gascad.at)
Date: 03/30/05
- Next message: Thomas Hansen: "Re: Correct C++ tutorial chapter 2.1 "Classes" available (Windows, mingw/msvc/std)"
- Previous message: Alf P. Steinbach: "Re: Correct C++ tutorial chapter 2.1 "Classes" available (Windows, mingw/msvc/std)"
- In reply to: tomailmelookatbottom_at_rediffmail.com: "Re: strang function pointer from faq book (help)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 30 Mar 2005 10:36:22 +0200
tomailmelookatbottom@rediffmail.com wrote:
>
> [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
> argument
> ^^^^^^^^^^^^^^^^^^^^^^^
> > 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).
Consider:
Your program has to work with arrays of 'long unsigned int' all over
the places. Eg.
int main()
{
long unsigned int a[20][40];
...
}
Now you get tired of typing this monster all the time. Thus you define
a typedef for it:
typedef long unsigned int UIntAr[20][40];
which makes UIntAr a second name for the data type 'long unsigned int [20][40]'.
Then you can write:
int main()
{
UIntAr a;
...
}
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 kbuchegg@gascad.at
- Next message: Thomas Hansen: "Re: Correct C++ tutorial chapter 2.1 "Classes" available (Windows, mingw/msvc/std)"
- Previous message: Alf P. Steinbach: "Re: Correct C++ tutorial chapter 2.1 "Classes" available (Windows, mingw/msvc/std)"
- In reply to: tomailmelookatbottom_at_rediffmail.com: "Re: strang function pointer from faq book (help)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|