首页 > 其他 > 详细

go 结构体函数

时间:2020-06-07 00:08:31      阅读:45      评论:0      收藏:0      [点我收藏+]
package main

import "fmt"

type Dog struct {
	Name string
}

func (d *Dog) speak() string  {
	return "I am a dog and my name is "+ d.Name
}

func TestStruct()  {
	d := Dog{Name:"killy"}
	st := d.speak()

	fmt.Println(st)
}

func main()  {

	TestStruct()

}

 

结果

GOROOT=/usr/local/go #gosetup
GOPATH=/www/gopath #gosetup
/usr/local/go/bin/go build -i -o /private/var/folders/fc/4txmmczj6q92p6058h3w7t_80000gn/T/___go_build_main_go__2_ /www/go/learn/main.go #gosetup
/private/var/folders/fc/4txmmczj6q92p6058h3w7t_80000gn/T/___go_build_main_go__2_ #gosetup
i am a dog my name is killy

Process finished with exit code 0

go 结构体函数

原文:https://www.cnblogs.com/php-linux/p/13057551.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!