Address of a temporary in Go?

后端 未结 8 881
不知归路
不知归路 2021-02-01 13:24

What\'s the cleanest way to handle a case such as this:

func a() string {
    /* doesn\'t matter */
}

b *string = &a()

This generates the

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-01 13:52

    a() doesn't point to a variable as it is on the stack. You can't point to the stack (why would you ?).

    You can do that if you want

    va := a()
    b := &va
    

    But what your really want to achieve is somewhat unclear.

提交回复
热议问题