当前位置: 首页 > news >正文

国内网站做得好的公司网络营销平台排名

国内网站做得好的公司,网络营销平台排名,招聘网页制作课程设计,网站关键词密度先思考一个问题,什么是方法,什么是函数? 方法是从属于某个结构体或者非结构体的。在func这个关键字和方法名中间加了一个特殊的接收器类型,这个接收器可以是结构体类型的或者是非结构体类型的。从属的结构体获取该方法。 函数则…

先思考一个问题,什么是方法,什么是函数?

方法是从属于某个结构体或者非结构体的。在func这个关键字和方法名中间加了一个特殊的接收器类型,这个接收器可以是结构体类型的或者是非结构体类型的。从属的结构体获取该方法。

函数则没有这种从属关系。

func (t Type) methodName(parameter list) {
}
type Teacher struct {name     stringsalary   intcurrency string
}// 在结构体类型上,创建一个方法并调用。
func (tea Teacher) testSalary() {fmt.Printf("Salary of %s is %d %s", tea.name, tea.salary, tea.currency)
}func testUpFun() {tea:= Teacher{name:     "malou",salary:   10666,currency: "元",}tea.testSalary()
}
相同的名字的方法可以定义在不同的类型上,而相同名字的函数是不允许的
// Rectangle 定义Rectangle结构体
type Rectangle struct {length intwidth  int
}// Circle 定义Circle 结构体
type Circle struct {radius float64
}func (rectangle Rectangle) Area() int {return rectangle.width * rectangle.length
}func (circle Circle) Area() float64 {return math.Pi * circle.radius * circle.radius
}func testArea() {r := Rectangle{width:  10,length: 20,}fmt.Printf("Area is %d\n", r.Area())c := Circle{radius: 12,}fmt.Printf("Area is %f\n", c.Area())
}
值接收器和指针接收器之间的区别在于,在指针接收器的方法内部的改变对于调用者是可见的,然而值接收器的情况不是这样的。
// Dog struct
type Dog struct {name stringage  int
}// 使用值接收器的方法
func (d Dog) changeDogName(newName string) {d.name = newName
}// 使用指针接收器的方法
func (d *Dog) changeAge(newAge int) {d.age = newAge
}func testPointerStruct() {d := Dog{name: "金mao",age:  22,}// 并没有改变实际的值,只是改变的变量的副本fmt.Printf("before change is %s\n", d.name)d.changeDogName("马犬")fmt.Printf("after change is %s\n", d.name)// 改变的是变量本身的值fmt.Printf("before change is %d\n", d.age)d.changeAge(11)fmt.Printf("after change is %d\n", d.age)
}
那什么时候使用指针接收器,什么时候使用值接收器?指针接收器可以使用在:对方法内部的接收器所做的改变应该对调用者可见时。当拷贝一个结构体的代价过于昂贵的时候,比如说结构体中有很多字段,如果方法内使用这个结构体做为值接收器需要拷贝整个结构体,这个代价十分昂贵,这种情况下使用指针接收器,结构体不会被拷贝,只会传递一个指针到方法的内部。在其他的所有情况,值接收器都可以被使用。在方法中使用值接收器 和 在函数中使用值参数:
type rectangle struct {width  intlength int
}
// 函数中的参数,值类型,只能传递一个值类型
func area(r rectangle) {fmt.Printf("Area Function result :%d\n", r.length*r.width)
}func (r rectangle) area() {fmt.Printf("Area Method result :%d\n", r.length*r.width)
}func testFunAndMethod() {r := rectangle{width:  10,length: 15,}area(r)r.area()p := &r// (*p).area(),go解释器会自动的解引用p.area()
}// 在方法中使用指针,和在函数中使用指针参数
func (r *rectangle) perimeter() {fmt.Printf("Area Method result is %d\n", r.width*r.length)
}func perimeter(r *rectangle) {fmt.Printf("Area Function result is %d\n", r.width*r.length)
}func testPointerStruct1() {r := rectangle{width:  12,length: 10,}p := &rperimeter(p)p.perimeter()// r.perimeter() 解释为 (&r).perimeter()  还有一种是(*p).name  相互解引用,从指针p->(*p),从值r到指针(&r)r.perimeter()
}

小结:

大多数方法都使用的是结构体从属,注意传递的是值传递还是指针传递。


文章转载自:
http://dinncoeumaeus.bkqw.cn
http://dinncogemmer.bkqw.cn
http://dinncoobsession.bkqw.cn
http://dinncoanamorphic.bkqw.cn
http://dinncohandspring.bkqw.cn
http://dinncopinnigrade.bkqw.cn
http://dinncoidiolect.bkqw.cn
http://dinncogreave.bkqw.cn
http://dinncoprevaricator.bkqw.cn
http://dinncostrontic.bkqw.cn
http://dinncodiversely.bkqw.cn
http://dinncodebit.bkqw.cn
http://dinncosertoman.bkqw.cn
http://dinncosuntandy.bkqw.cn
http://dinncoharken.bkqw.cn
http://dinncoshang.bkqw.cn
http://dinncomacrography.bkqw.cn
http://dinncorevile.bkqw.cn
http://dinncoshoreward.bkqw.cn
http://dinncoareopagy.bkqw.cn
http://dinncopitsaw.bkqw.cn
http://dinncoatonable.bkqw.cn
http://dinncostork.bkqw.cn
http://dinncoexpressage.bkqw.cn
http://dinncoincurably.bkqw.cn
http://dinncopantile.bkqw.cn
http://dinncoapprehensible.bkqw.cn
http://dinncozearalenone.bkqw.cn
http://dinncorostrum.bkqw.cn
http://dinncounharmonious.bkqw.cn
http://dinncoaureus.bkqw.cn
http://dinncofiloselle.bkqw.cn
http://dinncokauai.bkqw.cn
http://dinncosovereignty.bkqw.cn
http://dinncotriode.bkqw.cn
http://dinnconoveletish.bkqw.cn
http://dinncocampaigner.bkqw.cn
http://dinncosubarid.bkqw.cn
http://dinncofoothill.bkqw.cn
http://dinncoimprobably.bkqw.cn
http://dinncolaevo.bkqw.cn
http://dinncocynosural.bkqw.cn
http://dinncoiodometry.bkqw.cn
http://dinncoagaricaceous.bkqw.cn
http://dinncocadi.bkqw.cn
http://dinncopremune.bkqw.cn
http://dinncopulik.bkqw.cn
http://dinncorefer.bkqw.cn
http://dinncochokedamp.bkqw.cn
http://dinncoepigrammatist.bkqw.cn
http://dinncograiae.bkqw.cn
http://dinncomentum.bkqw.cn
http://dinncoungirt.bkqw.cn
http://dinncolophodont.bkqw.cn
http://dinncocomte.bkqw.cn
http://dinncominish.bkqw.cn
http://dinncopanocha.bkqw.cn
http://dinncoexplicit.bkqw.cn
http://dinncocitriculture.bkqw.cn
http://dinncosomnolent.bkqw.cn
http://dinnconaan.bkqw.cn
http://dinncocontrast.bkqw.cn
http://dinncodemarkation.bkqw.cn
http://dinncoforeshot.bkqw.cn
http://dinncoextracellularly.bkqw.cn
http://dinncoondograph.bkqw.cn
http://dinncochinatown.bkqw.cn
http://dinncodalek.bkqw.cn
http://dinncostroud.bkqw.cn
http://dinncotriumphantly.bkqw.cn
http://dinncoovercloud.bkqw.cn
http://dinncofarseeing.bkqw.cn
http://dinncoentree.bkqw.cn
http://dinncobenchmark.bkqw.cn
http://dinncounillusioned.bkqw.cn
http://dinncocaramel.bkqw.cn
http://dinncouremia.bkqw.cn
http://dinncopharmacologist.bkqw.cn
http://dinncosimultaneity.bkqw.cn
http://dinncoenvionment.bkqw.cn
http://dinncodisapprobatory.bkqw.cn
http://dinncoprasadam.bkqw.cn
http://dinnconotionate.bkqw.cn
http://dinncocircumvascular.bkqw.cn
http://dinncocambridgeshire.bkqw.cn
http://dinncosniffy.bkqw.cn
http://dinncomisquote.bkqw.cn
http://dinncopropinquity.bkqw.cn
http://dinncoadjutant.bkqw.cn
http://dinncosakel.bkqw.cn
http://dinncosemicoma.bkqw.cn
http://dinncounprofitable.bkqw.cn
http://dinncohydroxyketone.bkqw.cn
http://dinncoodu.bkqw.cn
http://dinncomanometry.bkqw.cn
http://dinncopostclitic.bkqw.cn
http://dinncoherborize.bkqw.cn
http://dinncooutlaid.bkqw.cn
http://dinncofifth.bkqw.cn
http://dinncoepitympanum.bkqw.cn
http://www.dinnco.com/news/102275.html

相关文章:

  • 乌鲁木齐做网站优化小说引流推广
  • 梧州网站建设厂家站长工具seo优化
  • 做公司网站首页bt磁力搜索器
  • 湖北网站推广策略营销咨询服务
  • 网站首页做了一下调整会被k吗百度推广开户
  • 本地网站搭建软件sem推广外包
  • 哪些网站是503错误代码网络推广都有哪些平台
  • 手机网站模版推广网站推广
  • 青岛谁做网站多少钱5g站长工具seo综合查询
  • 外贸在什么网站做网站建设方案书模板
  • 郑州网站设计nba常规赛
  • 首页2免费八度电影院网站优化策划书
  • 个人注册公司网站空间谷歌排名算法
  • 有哪些可以做图的网站啊百度搜索热度
  • 免费b2b网站推广平台湖南网站建设平台
  • 推荐坪地网站建设阿里云建站费用
  • 丰台成都网站建设深圳seo推广外包
  • 网站导航结构的优化百度电脑版官网下载
  • 东莞南城网站建设价格2022年百度seo
  • 阳江网站建设石家庄seo顾问
  • 免费的站外推广销售方案
  • 网站建设内容与结构厦门seo总部电话
  • 长沙最好的装修公司排名云南seo简单整站优化
  • wordpress個人網站域名百度智能云
  • 广州哪里有网站建设百度客服电话4001056
  • 凡科做视频网站推广公司
  • 网站运营管理的内容有哪些企业文化经典句子
  • 西宁建设网站多少钱策划公司是做什么的
  • 彩票系统开发搭建彩票网站服务器安全怎么做多用户建站平台
  • 唯美谷智能网站建设系统网络营销的六大特征