Re: Stroustrup chapter 5, pointer to pointer to char
On Mar 6, 10:59 am, adrian.hawry...@gmail.com wrote:
On Mar 6, 9:47 am, Lionel B <m...@privacy.net> wrote:
On Tue, 06 Mar 2007 04:14:57 -0800, adrian.hawryluk wrote:
On Mar 5, 2:07 pm, "mlimber" <mlim...@gmail.com> wrote:
On Mar 5, 12:15 pm, "arnuld" <geek.arn...@gmail.com> wrote:
i see the use of pointers, from K&R2 but what is the use of:
[snip]
2. pointer to function:
int (*fp) (char*);
These are useful for callbacks, generic programming (e.g. with
std::for_each), etc. See also "functors".
Noooooooooo! This is a function pointer. Functors are related to
objects as in:
[snip]
mlimber didn't say "This is a function pointer", s/he said "See also
functors" - but didn't say why!
Sorry but he did, although it wasn't intentional.
Read it again. The OP called it a "pointer to function" and asked
"What's the use of it?" I said "These [antecedent: 'pointer[s] to
function[s]'] are useful for [sample uses]." I then suggested the OP
also look into functors, which have some definite affinities to
function pointer, particularly in generic programming. I did not in
any way say the two were identical.
(BTW, I think Lionel B. meant to say, "mlimber didn't say, 'This is a
functor.'")
Well, I found it unclear.
YMMV.
The comma between "callback" and "generic
programming" is clearly an implied conjunction with the parenthesis
showing an example on how it can be used.
Right. It was a list of uses. Stripping the parenthetical and
translating the abbreviation, the list was callbacks, generic
programming, and others.
I don't see what the etc
was referring to either. "These are useful for callbacks, generic
programming, "... and what? Are there other reasons to use a function
pointer?
You yourself gave other concrete examples -- one being a virtual
table, which one could also create explicitly, though not as
naturally, as a member of a struct.
If I misunderstood the sentence, it was because it was just
poorly formed and was hard to read.
I disagree, but you're certainly entitled to your opinion. :-)
Oh, and although functors are perhaps a more 'elegant' way of
representing a function pointer, it is actually not a function
pointer. It is an object with a function *like* interface and is why
it is called a functor not a function pointer.
No one has said differently here.
[snip]
Cheers! --M