我在Go中创建指向地图的指针时遇到了一些麻烦.如果我正确传递map参数,你能告诉我吗?它将整数值与结构对.
type symbol_table struct{
---
---
---
}
//is the map parameter being called correctly?
func TD(..., symbolMAP *map[int]symbol_table, ...){
---
---
---
}
func main(){
symbolMAP:=make(map[int] symbol_table)
TD(&symbolMAP)
}
Run Code Online (Sandbox Code Playgroud) 这是学习的最让我困惑的地方.我们都知道方法T只影响副本T,而方法*T会影响实际数据T.
为什么方法T也可以使用*T,但不允许相反?所以,你可以给我为什么他们不允许对方法的示例(或原因)*T被使用T?
这个设计的优点和缺点是什么?
我有这个代码,
// The prime sieve: Daisy-chain Filter processes.
func main() {
ch := make(chan int) // Create a new channel.
go Generate(ch) // Launch Generate goroutine.
for i := 0; i < 10; i++ {
prime := <-ch
print(prime, "\n")
ch1 := make(chan int)
go Filter(ch, ch1, prime)
ch = ch1
}
}
Run Code Online (Sandbox Code Playgroud)
我想了解通道分配的含义.例如ch = ch1,这是做什么的?深拷贝还是浅拷贝?这有什么保证?
谢谢