3 回答

TA贡献1868条经验 获得超4个赞
请不要投反对票,但我想表达一个简单的代码来重现您可能遇到的情况。(我没有使用 Thrift 的经验,但我认为它更多地与包有关)
package main
import (
"fmt"
"D"
)
type Foo struct {}
func (f *Foo) PrintIt() {
fmt.Println("Sample printing")
}
type Bar struct {
// For the sake of this experiment
X *D.Foo
}
func (b *Bar) PrintFromBar() {
// simulates b.x = D.NewFoo()
b.X = new(D.Foo)
b.X.PrintIt() // The culprit happens here
}
func main() {
b := new(Bar)
b.PrintFromBar()
}
D包:
package D
type Foo struct {}
b.PrintFromBar() 失败并显示“bXPrintIt 未定义(类型 *D.Foo 没有字段或方法 PrintIt)”。
问题可能在于D.NewFoo()创建名为Foofor的别名*D.Foo。在你的情况下,因为你的Read()方法已经在 D 包中,如果没有完整的代码,我不知道。然而,有趣的是这实际上会产生相同的错误。
- 3 回答
- 0 关注
- 225 浏览
添加回答
举报