大家好,新手问个写结构体方法值传递的问题

imzdj · · 1650 次点击
三个都运行正常且结果正确 但是如果: type Integer int func (a *Integer) Add(b Integer) { a += b } 就报错了,这是为啥??
#1
更多评论
polaris
社区,需要你我一同完善!
Go 编译器会自动做这种转换。查看Go语言规范:http://docs.studygolang.com/ref/spec#Struct_types 或 中文版: http://docscn.studygolang.com/ref/spec.old#结构类型 而 `a += b` 属于指针和 int 相加,Go 不支持指针运算。
#2
好!马上去瞧瞧,谢谢你这么好的资源,太感谢你了!!
#3