标签:
func (c App) example() // 类似于类方法,c为局部变量,对其修改不影响对象的值
func (c *App) example() // 成员方法,操作对象本身
package main import ( "fmt" ) type App struct{ Name string Num int } func (c *App)getName(){ c.Name = "myname" } func (c App)getNum()App{ c.Num = 11 return c } func main() { app := &App{} app.getName() app2 := app.getNum() fmt.Println(app,app2) } /* app: &{myname 0} app2: {myname 11} */
golang func (c AppController) example() 和func (c *AppController) example() 区别
标签:
原文地址:http://www.cnblogs.com/benlightning/p/4448125.html