import "fmt"
type Rect struct {
x, y float64
width, height float64
}
func (r **Rect) Area() float64 {
return (*r).width * (*r).height
}
func main(){
rect3 := &Rect{0, 0, 100, 200}
(*rect3).width =10;
var rect3qq **Rect = &rect3
fmt.Printf("Type of rect3qq is %T\n", rect3qq)
// fmt.Println("&:",rect3,"*:",*rect3,Rect,*Rect)
}
输出
$ go run /c/Users/Administrator/Desktop/GoTest/GoClass.go
# command-line-arguments
.\GoClass.go:8:6: invalid receiver type **Rect (*Rect is an unnamed type)
golang支持最多几级的指针
有疑问加站长微信联系(非本文作者)