如果这个基本问题已经得到回答,我们深表歉意。我应该在 print()
的括号内放什么,以便第一个参数保留为默认值,但以下参数被赋予新值 1 和 2?我知道我可以从字面上把 0 放在那里但是有没有办法让它变成默认值?
#include<iostream>
using namespace std;
void printer(int a=0, int b=0, int c=0){
cout << a << endl;
cout << b << endl;
cout << c << endl;
}
int main(){
//leave a=0 and replace both b and c
printer(/*?*/,1,2);
return 0;
}
最佳答案
你不能那样做,这是不允许的。只有右边大部分参数可以省略。
关于c++ - 如何在 C++ 中将前面的函数参数设置为其默认值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16000462/