Re: strang function pointer from faq book (help)
From: Karl Heinz Buchegger (kbuchegg_at_gascad.at)
Date: 03/29/05
- Next message: Uenal Mutlu: "Re: modifying stack variable"
- Previous message: Alf P. Steinbach: "Re: array of pointers"
- In reply to: tomailmelookatbottom_at_rediffmail.com: "strang function pointer from faq book (help)"
- Next in thread: tomailmelookatbottom_at_rediffmail.com: "Re: strang function pointer from faq book (help)"
- Reply: tomailmelookatbottom_at_rediffmail.com: "Re: strang function pointer from faq book (help)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 29 Mar 2005 17:25:55 +0200
tomailmelookatbottom@rediffmail.com wrote:
>
>
> I am having doubt with the line
>
> typedef void(Fred::*FredMemberPt)(int);
>
> In the above line I can able to understand that it is a declaration of
> pointer to a function which is typedef ed. I have seen using the scope
> resolution operator used to access the static variouble,member function
> definition outside the class(and lot more,yet to learn). But the above
> function name FredMemberPt does not exist in any of the code and yet it
> has been compiled with out any errors.
It is just an ordinary typedef.
Generally the rule works like this: Just write it as an ordinary
declaration eg.
int MyJ;
Then preceed the whole thing with 'typedef' and the name you define,
'MyJ', magically turns into a new data type name which is an alias
for the whole. So if you do
typedef int MyJ;
then MyJ gets an alias for the whole data type, in this case for 'int'.
In light of that
typedef void(Fred::*FredMemberPt)(int);
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.
It is used to get a more friendly writing a little bit down. To define
an actual function pointer one would need to write:
int main()
{
void (Fred::*gFnct)(int) = &Fred::g;
}
which defines gFnct to be a pointer to a member function of Fred. Instead of
that clumsy syntax, one introduces a typedef to make that whole thing
cleaner:
int main()
{
FredMemberPt gFnct = &Fred::g;
}
-- Karl Heinz Buchegger kbuchegg@gascad.at
- Next message: Uenal Mutlu: "Re: modifying stack variable"
- Previous message: Alf P. Steinbach: "Re: array of pointers"
- In reply to: tomailmelookatbottom_at_rediffmail.com: "strang function pointer from faq book (help)"
- Next in thread: tomailmelookatbottom_at_rediffmail.com: "Re: strang function pointer from faq book (help)"
- Reply: tomailmelookatbottom_at_rediffmail.com: "Re: strang function pointer from faq book (help)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|