Interestingly, it distinguishes two "similar functions" from each other and can be unambiguously called
This is what I learned from self-study.
Uniqueness comes from: Function name + Argument and argument name + return type. Their combination must be unique in order to make a unique function (see Example below)
Nmu1and Num2will cause ambiguity, because the return type (does not have a so-called return name, the function name already acts like this role) is not passed when the function is called
Although the function Num3has a different parameter name, it will not unambiguously separate it from the function in Num1and Num2. Since the argument name will not be passed when the function is called, only another argument name will not make the function unique; And the function from Num4is different from all the above functions, because its signature Function name + Order argument and argument name + return type are unique among all the previous three functions.
Num5and Num6functions differ from each other because they have different orders of arguments when they were defined
func foo(guy name: String) -> String {
return "Hi \(name)"
}
func foo(guy name: String) {
print("Hi \(name)")
}
func foo(guy called: String) -> String {
return "Hi \(called)"
}
func foo(dude name: String) -> String {
return "What up \(name)"
}
func foo(man name: String, from place: String) {
print("Hi! I'm \(name) I come from \(place)")
}
func foo(from place: String, man name: String) {
print("Hi! I'm \(name) I come from \(place)")
}
Question : I could have missed, or perhaps even misunderstood some parts. It would be very nice that you can correct me and add those parts that I missed.
thank
[]
. , . !
, . ; . . .
, , . .
, , .
func foo(dude name: String) -> Int {
print("Hi \(name)!")
return 1
}
func foo(man name: String) -> Int {
print("Hi \(name)!")
return 1
}
//foo(dude: String) & foo(man: String) is identical when calling