第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Go語(yǔ)言圣經(jīng)中函數(shù)調(diào)用的疑問(wèn)

Go語(yǔ)言圣經(jīng)中函數(shù)調(diào)用的疑問(wèn)

慕容3067478 2019-05-24 15:43:44
cf/main.go//Copyright?2016AlanA.A.Donovan&BrianW.Kernighan.//License:https://creativecommons.org/l...//Seepage43.//!+//CfconvertsitsnumericargumenttoCelsiusandFahrenheit.packagemainimport("fmt""os""strconv""gopl.io/ch2/tempconv")funcmain(){for_,arg:=rangeos.Args[1:]{t,err:=strconv.ParseFloat(arg,64)iferr!=nil{fmt.Fprintf(os.Stderr,"cf:%v\n",err)os.Exit(1)}f:=tempconv.Fahrenheit(t)c:=tempconv.Celsius(t)fmt.Printf("%s=%s,%s=%s\n",f,tempconv.FToC(f),c,tempconv.CToF(c))}}//!-tempconv/tempconv.go//Copyright?2016AlanA.A.Donovan&BrianW.Kernighan.//License:https://creativecommons.org/l...//!+//PackagetempconvperformsCelsiusandFahrenheitconversions.packagetempconvimport"fmt"typeCelsiusfloat64typeFahrenheitfloat64const(AbsoluteZeroCCelsius=-273.15FreezingCCelsius=0BoilingCCelsius=100)func(cCelsius)String()string{returnfmt.Sprintf("%g°C",c)}func(fFahrenheit)String()string{returnfmt.Sprintf("%g°F",f)}//!-tempconv/conv.go//Copyright?2016AlanA.A.Donovan&BrianW.Kernighan.//License:https://creativecommons.org/l...//Seepage41.//!+packagetempconv//CToFconvertsaCelsiustemperaturetoFahrenheit.funcCToF(cCelsius)Fahrenheit{returnFahrenheit(c*9/5+32)}//FToCconvertsaFahrenheittemperaturetoCelsius.funcFToC(fFahrenheit)Celsius{returnCelsius((f-32)*5/9)}//!-上面程序中的f:=tempconv.Fahrenheit(t)c:=tempconv.Celsius(t)是怎么調(diào)用的以下方法呢:func(cCelsius)String()string{returnfmt.Sprintf("%g°C",c)}func(fFahrenheit)String()string{returnfmt.Sprintf("%g°F",f)}這兩個(gè)方法都是有函數(shù)名String的。不太明白這個(gè)調(diào)用過(guò)程。
查看完整描述

2 回答

?
DIEA

TA貢獻(xiàn)1820條經(jīng)驗(yàn) 獲得超2個(gè)贊

許多類型都會(huì)定義一個(gè)String方法,因?yàn)楫?dāng)使用fmt包的打印方法時(shí),將會(huì)優(yōu)先使用該類型對(duì)應(yīng)的String方法返回的結(jié)果打印我明白了。。
                            
查看完整回答
反對(duì) 回復(fù) 2019-05-24
  • 2 回答
  • 0 關(guān)注
  • 661 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)