cloudaice / learnGo

there are something about Go Useage
MIT License
0 stars 0 forks source link

为类型添加方法时候注意事项 #3

Open cloudaice opened 11 years ago

cloudaice commented 11 years ago

为一个自己定义的类型添加方法的时候。一般使用以下方法:

func (t *typename) method() { }

记得在typename前面加*

这种情况下,无论实例是一个指针还是值,在调用的时候都正常运行,否则实例调用的时候需要严格匹配。