我正在将C库移植到Go。 C函数(带有varargs)的定义如下:

因此,我创建了包装器C函数:

如果我在Go中这样定义函数:

Go编译器抱怨:

那么Go支持功能(方法)重载了吗,还是这个错误意味着其他?


不,不是的。

请参阅Go语言常见问题解答,尤其是有关重载的部分。

Method dispatch is simplified if it doesn't need to do type matching as well. Experience with other languages told us that having a variety of methods with the same name but different signatures was occasionally useful but that it could also be confusing and fragile in practice. Matching only by name and requiring consistency in the types was a major simplifying decision in Go's type system.

尽管Go仍然没有重载函数(并且可能永远不会重载),但是重载最有用的功能是调用带有可选参数的函数,并为被省略的参数推断默认值,可以使用可变参数函数进行模拟,此函数现已添加。但这带来了类型检查的损失。

例如:http://changelog.ca/log/2015/01/30/golang


据此,它不会:http://golang.org/doc/go_for_cpp_programmers.html

在"概念差异"部分中,它表示:

" Go不支持函数重载,也不支持用户定义的运算符。"


func (e *Easy)SetOption(any []interface{})

该过程将参数转换为此空interface{}

首先进行转换,然后进行内部逻辑处理。

http://zerousm99.blogspot.kr/2015/01/golang-overload.html