hugo2 said:
obrhy[at]yahoo.com July 7, 2005
Suppose a user function is declared, prototyped f();,
where the () are empty.
And further, when the function is defined in a .CPP file
it has no params, f(){...}.
But when this function is called, invoked in the program
its call has an argument: f(*thresh1);
Correction: f(*thresh1) isn't a call to f() since the supplied parameter(s),
or lack thereof, are part of a function's signature.
The same condition exists if you define void f() and attempt to call it
with:
f(arg); // attempts to call void f(T t) where T is the arg's Type
If void f(T t) isn't defined, and no auto-conversion exists between supplied
and expected parameters, error ensues.
Beware if void f(int n) is defined and then:
double d;
f(d);
In the above statements, a silent cast from double to int is carried out (a
rather unfortunate situation in most cases). That silent cast is about as
loose as a C++ compliant compiler is allowed to get with respect to a
function call.
Would this be an error?
Or does the function have a way of accessing the arg(s)?
Its an error, but what needs to be noted is that the function definition
results in a signature. That signature is composed of the function name +
arguments and its usually padded by the compiler (the return type is *not*
part of the signature).
So instead of thinking of this call as a function call, think of it as a
reasonably strict function-signature calling mechanism (for lack of a better
phrase).
There is no way the compiler can deduce, inject or guess at what it should
do if unexpected parameters are provided (its not allowed to act
ambiguously). If C++ allowed this, overloading functions would not be
posssible. That is, void f(int n), void f(char c), void f(), etc all depict
unique signatures.