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

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

為什么你不能在 Go 中命名一個(gè)函數(shù)“init”?

為什么你不能在 Go 中命名一個(gè)函數(shù)“init”?

Go
哈士奇WWW 2021-08-16 15:55:26
所以,今天在我編寫代碼時(shí),我發(fā)現(xiàn)使用名稱創(chuàng)建一個(gè)函數(shù)會(huì)init產(chǎn)生一個(gè)錯(cuò)誤method init() not found,但是當(dāng)我將它重命名為startup它時(shí)一切正常。“init”這個(gè)詞是為 Go 中的某些內(nèi)部操作保留的,還是我在這里遺漏了什么?
查看完整描述

2 回答

?
大話西游666

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

您還可以查看使用initin時(shí)可能遇到的不同錯(cuò)誤golang/test/init.go


// Verify that erroneous use of init is detected.

// Does not compile.


package main


import "runtime"


func init() {

}


func main() {

    init() // ERROR "undefined.*init"

    runtime.init() // ERROR "unexported.*runtime\.init"

    var _ = init // ERROR "undefined.*init"

}

init本身由golang/cmd/gc/init.c:

現(xiàn)在在cmd/compile/internal/gc/init.go:


/*

* a function named init is a special case.

* it is called by the initialization before

* main is run. to make it unique within a

* package and also uncallable, the name,

* normally "pkg.init", is altered to "pkg.init·1".

*/


查看完整回答
反對(duì) 回復(fù) 2021-08-16
  • 2 回答
  • 0 關(guān)注
  • 195 瀏覽
慕課專欄
更多

添加回答

舉報(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)