假设有一个具有以下原型(prototype)的函数:
void fun (int = 10, int = 20, int = 30, int = 40);
如果这个函数是通过传递 2 个参数来调用的,我们如何确保这些参数被视为第一个和第三个,而第二个和第四个被视为默认值。
最佳答案
// three and four argument version
void fun (int a, int b, int c, int d = 40)
{
...
}
// two argument version
void fun (int a, int c)
{
fun(a, 20, c, 40);
}
// one and zero argument version
void fun(int a = 10)
{
fun(a, 20, 30, 40);
}
但实际上我的建议是不要。
关于c++ - 有没有办法确保传递给函数的两个参数在 C++ 中被视为第一个和第三个参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61585832/