相关疑难解决方法(0)

如何清楚地指定我传递的参数和哪些参数保持默认值?

因为这个问:c ++中的默认参数

说我有这样的功能: void f(int p1=1, int p2=2, int p3=3, int p4=4);

我想只使用一些参数调用它 - 其余的将是默认值.

像这样的东西会起作用:

template<bool P1=true, bool P2=true, bool P3=true, bool P4=true>
void f(int p1=1, int p2=2, int p3=3, int p4=4);
// specialize:
template<>
void f<false, true, false, false>(int p1) {
  f(1, p1);
}
template<>
void f<false, true, true, false>(int p1, int p2) {
  f(1, p1, p2);
}
// ... and so on. 
// Would need a specialization for each combination of arguments
// which is …
Run Code Online (Sandbox Code Playgroud)

c++ overloading default-arguments c++11

8
推荐指数
2
解决办法
731
查看次数

c ++中的默认参数

我是c ++的新手我对默认参数有疑问.如果有一个具有以下原型的功能

void f(int=10,int=20,int=30,int=40)
Run Code Online (Sandbox Code Playgroud)

如果通过向它传递2个参数来调用此函数,我们如何确保将这些argumnt视为第一个和第三个,而将第二个和第四个作为默认值.

c++

1
推荐指数
1
解决办法
1073
查看次数

如何只使用函数的一些可选参数

有没有办法只使用函数的一些可选参数?所以如果我有这样的功能,

void f(int a = 0, int b = 1) {}
Run Code Online (Sandbox Code Playgroud)

我可以调用f()并只指定b并保留a其默认值吗?

c++ function

1
推荐指数
1
解决办法
75
查看次数

标签 统计

c++ ×3

c++11 ×1

default-arguments ×1

function ×1

overloading ×1