为什么可选参数必须出现在声明的末尾 [英] Why optional parameters must appear at the end of the declaration

查看:292
本文介绍了为什么可选参数必须出现在声明的末尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在支持,我已经看到有一个模仿的可选参数必须出现在声明的末尾可选参数所有的编程语言。不需要参数可包括一个可选的项目之后。
是什么原因呢?我想这可能是编译器/解释的要求。

In all programming languages supporting optional parameters that I have seen there is a imitation that the optional parameters must appear at the end of the declaration. No required parameters may be included after an optional item. What is the reason for that ? I guess it can be compiler/interpreter requirement.

推荐答案

好吧,如果他们是在前面,你会怎么检测时,他们'已经不再是提供?唯一的办法是,如果变量的类型是不同的之后的可选参数。一个奇怪的要求一点,所以它是有道理的,你只是迫使他们是最后一个(节省检测最终可选参数的复杂规则的麻烦)。

Well, if they were at the front, how would you detect when they've stopped being supplied? The only way would be if the variable type was different after the optional parameters. Bit of a weird requirement, so it makes sense that you just force them to be last (save the trouble of complex rules for detecting the "final" optional parameter).

此外,它是最自然的方式调用函数时做到这一点。

Besides, it's the most natural way to do it when calling the function.

这篇关于为什么可选参数必须出现在声明的末尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆