5.3 Go语言中构造函数与复合声明(Constructors and composite literals)

Posted 孙琦Ray

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了5.3 Go语言中构造函数与复合声明(Constructors and composite literals)相关的知识,希望对你有一定的参考价值。

构造函数

单纯使用new进行初始化无法满足初始化需求,必须需要初始化的构造函数,例如以下这个例子:

func NewFile(fd int, name string) *File 
   
    if fd < 0 
   
        return nil
    
    f := new(File)

以上是关于5.3 Go语言中构造函数与复合声明(Constructors and composite literals)的主要内容,如果未能解决你的问题,请参考以下文章