我意識到Go沒有類,而是推送了structs的想法。結構是否具有可以類似于類的__construct()函數那樣調用的某種初始化函數?例子: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)
結構的初始化函數
ibeautiful
2021-04-30 10:07:06