我意識到Go沒有類,而是推送了structs的想法。結(jié)構(gòu)是否具有可以類似于類的__construct()函數(shù)那樣調(diào)用的某種初始化函數(shù)?例子:type Console struct { X int Y int}func (c *Console) init() { c.X = "5"}// Here I want my init function to runvar console Console// or here if I usedvar console Console = new(Console)
結(jié)構(gòu)的初始化函數(shù)
ibeautiful
2021-04-30 10:07:06