I
Irfy
Could someone elaborate on the purpose and concrete usage scenarios of
references to functions. What can references to functions do that
pointers to functions cannot. Why are they in C++?
A swap function with two reference parameters of the same type is a
typical example to explain the purpose of references to objects in C++
and the way they can be used, but since functions cannot be
"changed" (in the sense "exchange the bodies of functions foo and
bar"), I cannot think of an example making the purpose of references
to functions obvious. I guess I must be missing something.
I found a comment by Rob Williscroft in the Thread
http://groups.google.com/group/comp...st&q=references+to+functions#6c736d2133cf30dc
saying:
but I cannot not "see through" this exaplanation, why would a
reference to a function be more efficient, is this just a speculation?
-- Irfy
references to functions. What can references to functions do that
pointers to functions cannot. Why are they in C++?
A swap function with two reference parameters of the same type is a
typical example to explain the purpose of references to objects in C++
and the way they can be used, but since functions cannot be
"changed" (in the sense "exchange the bodies of functions foo and
bar"), I cannot think of an example making the purpose of references
to functions obvious. I guess I must be missing something.
I found a comment by Rob Williscroft in the Thread
http://groups.google.com/group/comp...st&q=references+to+functions#6c736d2133cf30dc
saying:
Yes, but you could also ask another question, why are references to
functions part of C++ since they don't provide any utility that
isn't provided by function pointers. I think the answer is that
it allows a simple function to behave like a 'functor', particularly
a 'reference to a functor', more efficiently. This is important for
the standard library algorithms.
but I cannot not "see through" this exaplanation, why would a
reference to a function be more efficient, is this just a speculation?
-- Irfy