显示为未定义的golang的方法
我试图从不同的目录调用一个方法,但收到一个错误,说明该方法不存在。我有第一个大写字母的方法 我有以下目录结构显示为未定义的golang的方法,go,Go,我试图从不同的目录调用一个方法,但收到一个错误,说明该方法不存在。我有第一个大写字母的方法 我有以下目录结构 [laptop@laptop src]$ tree . ├── hello │ ├── hello.go ├── remote_method │ └── remoteMethod.go 我的main在hello.go中,尝试从远程方法包调用函数 package main import ( "remote_method" ) func main() {
[laptop@laptop src]$ tree
.
├── hello
│ ├── hello.go
├── remote_method
│ └── remoteMethod.go
我的main在hello.go中,尝试从远程方法包调用函数
package main
import
(
"remote_method"
)
func main() {
mm := remote_method.NewObject()
mm.MethodCall()
}
remoteMethod.go包含以下内容
package remote_method
import (
.....
)
type DeclaredType struct {
randomMap (map[string][](chan int))
}
func NewObject() DeclaredType {
var randomMap (map[string][](chan int))
m := DeclaredType{randomMap}
return m
}
func MethodCall(m DeclaredType, param1 string, param2 string, param3 string, param4 string) {
// Code to be run
}
我得到了错误
mm.MethodCall undefined (type remote_method.DeclaredType has no field or method MethodCall)
有人能帮我找到为什么这个方法不可见或者我能找到的任何可能的方法吗。
TIA将MethodCall()注册为DeclaredType中的接收方
远程方法。转到
package remote_method
import (
.....
)
type DeclaredType struct {
randomMap (map[string][](chan int))
}
func NewObject() DeclaredType {
var randomMap (map[string][](chan int))
m := DeclaredType{randomMap}
return m
}
func (d DeclaredType) MethodCall(m DeclaredType, param1 string, param2 string, param3 string, param4 string) {
// Code to be run
}
well
MethodCall
不是您的DeclaredType
结构的成员请看一下,方法声明解释得很好。