Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use unnamed function arguments in C or C++

How do I use function arguments declared like

void f(double)
{
    /**/
}

if it is possible?

like image 509
zed91 Avatar asked Mar 22 '10 07:03

zed91


1 Answers

I hope an example can provide some help:

// Declaration, saying there is a function f accepting a double.
void f(double);

// Declaration, saying there is a function g accepting a double.
void g(double);

// ... possibly other code making use of g() ... 

// Implementation using the parameter - this is the "normal" way to use it. In
// the function the parameter is used and thus must be given a name to be able
// to reference it. This is still the same function g(double) that was declared
// above. The name of the variable is not part of the function signature.
void g(double d)
{
  // This call is possible, thanks to the declaration above, even though
  // the function definition is further down.
  f(d);
}

// Function having the f(double) signature, which does not make use of 
// its parameter. If the parameter had a name, it would give an 
// "unused variable" compiler warning.
void f(double)
{
  cout << "Not implemented yet.\n";
}
like image 168
Anders Abel Avatar answered Sep 27 '22 21:09

Anders Abel