I'm with MikeyBoy -- I don't see the point of this syntax for function calls.
function(int b);// function call
What do expect it to do?
If it was possible, b in unititialized in your example, and the trivial case
function(int b = 3); // set b to 3, call function with b (= 3)l
would be the same as
function(3);
and a less trivial case
function(int b = 2 * other_funct(5));
the same as
function(2 * other_funct(5));
So I really don't see why the syntax is needed (or is needed to be valid).
As it stands, when you have a function declared as
int f(int a);
, when you call it, the parameter (a in this case) is set to the contents of the brackets (similarly for other parameters, it present). And a is at function scode, unless it's a reference parameter. So doesn't that do what you require?
And
function(int b = 3);
still looks like a function
declaration to the compiler (one which is missing it's return type). But now the parameter b has a default value.
And, while function definitions aren't allowed at function scope, forward declarations are.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#include <iostream> // For stream I/O
using namespace std;
int main()
{
int times_two(int b = 2); // forward declaration
cout << times_two() << endl;
cout << times_two(3) << endl;
return 0;
}
int times_two(int a /*= 2*/)
{
return 2 * a;
}
|
It's not something I've seen very ofter outside of examples. But it is a way of controlling which functions can use another one.
Andy