A Tour of Go The new function

The expression new(T) allocates a zeroed T value and returns a pointer to it.

var t *T = new(T)

or

t := new(T)

package main 

import "fmt"

type Vertex struct { 
    X,Y int
}
func main() {
    v :=new(Vertex)
    fmt.Println(v)
    v.X, v.Y = 11, 9
    fmt.Println(v)
}

 

posted @ 2014-10-27 00:50  wuhn  阅读(132)  评论(0编辑  收藏  举报