
本文介绍了指向地图的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将一些贴图定义为:
var valueToSomeType = map [uint8] someType {...}
var nameToSomeType = map [string] someType {...}
我想要一个变量指向地图的地址(不要复制所有变量)。我试过它:
valueTo:=& valueToSomeType
nameTo:=& nameToSomeType
但使用 valueTo [number]
时,它显示
内部编译器错误:var without type,init:new
如何获取它?
编辑
错误是由另一个问题所显示的。 h2_lin>解决方案
地图是引用类型,因此它们都是通过引用传递的。你不需要指针。
Having some maps defined as:
var valueToSomeType = map[uint8]someType{...}
var nameToSomeType = map[string]someType{...}
I would want a variable that points to the address of the maps (to don't copy all variable). I tried it using:
valueTo := &valueToSomeType
nameTo := &nameToSomeType
but at using valueTo[number]
, it shows
internal compiler error: var without type, init: new
How to get it?
Edit
The error was showed by another problem.
解决方案
Maps are reference types, so they are allways passed by reference. You don't need a pointer.
这篇关于指向地图的指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!