谁能告诉我这段代码有什么问题?
package main
import "fmt"
type Document struct{
testString string
}
type Printer interface{
Print(d *Document)
}
type Scanner interface{
Scan(d *Document)
}
type MultiFunctionMachine struct{
printer Printer
scanner Scanner
}
func (m *MultiFunctionMachine)Print(d *Document){
m.printer.Print(d)
}
func main(){
doc:= Document{"test"}
multiMachine:= MultiFunctionMachine{}
multiMachine.Print(&doc)
}
我无法弄清楚为什么它一直抛出这个以下错误。指针似乎有问题。
*panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1092b46]
goroutine 1 [running]:
main.(*MultiFunctionMachine).Print(...)
/Users/dmml/Documents/golang/udemyGoCourses/designPatternInGo/solidDesignPrinciples/interfaceSegrationPrinciple/main.go:85
main.main()
/Users/dmml/Documents/golang/udemyGoCourses/designPatternInGo/solidDesignPrinciples/interfaceSegrationPrinciple/main.go:94 +0x46
exit status 2*