Re: pointer to a function?
Fraser Ross wrote:
My example has code similar to this from Effective STL:
int g(double ());
The book says that the parameter double() is a pointer to a function.
I'm not sure I agree with that terminology. If we had this:
double(*funcPtr)();
then we can say that "funcPtr is a pointer to a function". That's
because "funcPtr" is an actual variable, an actual pointer.
With "int g(double());" you are only declaring a function named g, as
a function taking a function pointer and returning an int. You are not
actually declaring an actual function pointer anywhere. Thus I'm not
sure I agree with saying "double() is a pointer to a function". It's not
a pointer, it's only a declaration.
If you said "in this expression double() declares a function pointer
type" then it would be, IMO, more accurate.
My example has code similar to this from Effective STL:
int g(double ());
Your example was maybe similar on a quick glance, but the extra
parentheses in your example make a whole lot of a difference. They make
your code to have a completely different meaning than that.
"int g(double());" and "int g((double()));" are two completely
different expressions which have absolutely nothing in common (except
for the name 'g'). The first declares a function, the second
instantiates a variable of type int and initializes it to the default
initialization value of double.
Just because those two expressions may look similar doesn't mean they
actually are.