c++ - 如何在 C 或 C++ 中使用未命名的函数参数

标签 c++ function arguments

我如何使用像这样声明的函数参数

void f(double)
{
    /**/
}

如果可能的话?

最佳答案

我希望一个例子可以提供一些帮助:

// 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";
}

关于c++ - 如何在 C 或 C++ 中使用未命名的函数参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2490456/

相关文章:

c++ - _IO_wide_data_2 : what's this?

C++ 抽象基类后缀运算符

c - 为什么数组的元素打印不正确?

PHP 调用 function_exists 中的函数

Python:从函数中减去一个 float (为了调用 scipy.newton())

c++ - Qt5.6设置应用程序图标(Linux)

c++ - 将一个包含很多类的文件转换为每个文件一个类的多个文件

arrays - 如何将一组未知数量的参数传递给 MATLAB 中的函数?

javascript - 反转所有参数 JS

list - 无限制列表的elem函数