Pointer operator -> for golang

go, operator-keyword, pointers

Solution

In Go, both `->` and `.` are represented by `.`

The compiler knows the types, and can dereference if necessary.

package main

import "fmt"

type A struct {
    X int
}

func main() {
    a0, a1 := A{42}, &A{27}
    fmt.Println(a0.X, a1.X)
}

Problem

It seems golang does not have the pointer operator -> as C and C++ have. Now let's say I have a function looks something like this: myfun(myparam *MyType), inside the function, if I want to access the member variables of MyType, I have to do (*myparam).MyMemberVariable. It seems to be a lot easier to do myparam->MyMemberVariable in C and C++. I'm quite new to go. Not sure if I'm missing something, or this is not the right way to go? Thanks.

Original source