默认参数:是否只能保留最后一个参数? [英] Default parameters: can only the last argument(s) be left?
本文介绍了默认参数:是否只能保留最后一个参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道有可能做类似的事情:
int foo(int a = 0, int b = 1) { return a + b; }
,然后在不使用默认参数的情况下使用它,例如:
and then use it without the default parameters eg.:
foo(); // a = 0, b = 1 -> 1
或最后一个为默认值,例如:
or with the last one as default eg.:
foo(2); // a = 2 and b = 1 default -> 3
但是我的问题是:是否可以使用第一个参数(a)的默认值并给出第二个参数(b)的值
But my question is: Is it possible to use the default value for the first argument (a) and give the value of the second (b)
我的第一个想法是这样做(无效!):
My first thought was doing it like (which doesn't work!):
foo(,2); // a = 0 default and b = 2
是否存在这种语法还是这不可能?
Does a syntax for this exist or is this just not possible ?
推荐答案
否,在当前语法中是不可能的.
No, it is not possible in current syntax.
这篇关于默认参数:是否只能保留最后一个参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文