0

This is a copy paste from this page: Is there a difference in C++ between copy initialization and direct initialization?

A c3(A());

[...]

The third creates a function declaration for a function c3 that returns an A and that takes a function pointer to a function reurning a A (Read 8.2).

I thought the following was the proper syntax for a function pointer taking no parameter and returning A.

A c3( A (*pFunction)() );

Are the two syntaxes equivalent?

Community
  • 1
  • 1
usual me
  • 8,338
  • 10
  • 52
  • 95

1 Answers1

0

Yes. In function declarations, you can omit the argument names. You can even omit them in the definition, but then you can't use them. This avoids the "unused parameter" warnings of e.g. gcc.

EDIT As OP pointed out, my argument is not correct because of the missing * which I overlooked. The reason for the interpretation of A() as pointer to function lies in section 8.2.7 of the standard, where this ambiguous expression is defined to mean pointer to function.

arne
  • 4,514
  • 1
  • 28
  • 47
  • Is the * symbol part of the argument name as well? – usual me Oct 24 '13 at 09:34
  • Read 8.2.7 of the standard: It says that this is an ambiguity that has to be resolved as pointer to function. So my reasoning is not quite correct. I'll update the answer. – arne Oct 24 '13 at 09:47