menu

hjk41的日志

Avatar

Effective Note 24: function overloading vs parameter defaulting

The confusion over function overloading and parameter defaulting stems from the fact that they both allow a single function name to be called in more than one way.
So which should we use then?
The answer depends on two other questions. First, is there a value that you can use as a default? Second, how many algorithms do you want to use?
If there is a value that you can use as a default, and you are using only one algorithm, then you can choose parameter defaulting. Otherwise, you have to use function overloading.

评论已关闭