如何在 C 或 C++ 中使用未命名的函数参数 [英] How to use unnamed function arguments in C or C++
本文介绍了如何在 C 或 C++ 中使用未命名的函数参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用像
void f(double)
{
/**/
}
如果有可能?
推荐答案
我希望一个例子可以提供一些帮助:
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";
}
这篇关于如何在 C 或 C++ 中使用未命名的函数参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文