unsafe

作者: 进击云原生 | 来源:发表于2018-06-07 16:18 被阅读0次

go语言原则上不允许两个不同指针类型的值,例如 int64和 float64转换。

var a int64=64
an:=&a
b:=(*float64)(an)

这里会报错:cannot convert an (type *int64) to type *float64

Pointer主要适用于简单类型,如int,string,float等,对复杂的类型,比如:struct就不适用,得用type assertion类型断言来实现。
在gohello工程下建一个util的包,然后建一个mystruct的go文件,建一个user的struct

相关文章

网友评论

      本文标题:unsafe

      本文链接:https://www.haomeiwen.com/subject/nqigsftx.html