I have the following code:
package main
type Vertex struct {
X, Y float64
}
type VertexPointer *Vertex
func main() {
v := Vertex{3, 4}
v_ptr := &v
var test_1 *Vertex = &v
var test_2 **Vertex = &v_ptr
var test_3 VertexPointer = &v
var test_4 *VertexPointer = &v_ptr
}
When I try and run it (I'm using Go 1.6.2) I get the following error:
# command-line-arguments
./pointers.go:17: cannot use &v_ptr (type **Vertex) as type *VertexPointer in assignment
I'm confused why the assignment involving test_3
works but not test_4
. Based on what I've been reading, my understanding is that either both assignments should work or neither of them should work. Isn't the described behaviour a bit inconsistent?