在另一个方法中调用的方法调用未解决的引用。

huangapple go评论92阅读模式
英文:

Unresolved reference of a method call in another method

问题

我想从Seed方法中调用两个方法(seedAccounts和initializeBucket)。有没有办法做到这一点?它一直显示"未解析的引用"。

以下是代码:

type BoltClient struct {
    boltDB *bolt.DB
}

func (bc *BoltClient) Seed() {
    bc.initializeBucket() // 未解析的引用 initializeBucket
    bc.seedAccounts() // 未解析的引用 seedAccounts
}

func (bc *BoltClient) initializeBucket() {
    // 代码
}

func (bc *BoltClient) seedAccounts() {
    // 代码
}
英文:

I want to call two methods(seedAccounts and initializeBucket) from the Seed method. Is there a way to do it? It keeps saying "Unresolved reference".

Here is the code

type BoltClient struct {
    boltDB *bolt.DB
}

func (bc *BoltClient) Seed() {
    initializeBucket() //unresolved reference initializeBucket
    seedAccounts() // unresolved reference seedAccounts
}

func (bc *BoltClient) initializeBucket() {
    //Code
}

func (bc *BoltClient) seedAccounts() {
    //Code
}

答案1

得分: 5

initializeBucket()seedAccounts()BoltClient类型的方法,快速修复:

func (bc *BoltClient) Seed() {
     bc.initializeBucket() 
     bc.seedAccounts()
}

initializeBucket()seedAccounts()BoltClient类型的方法,快速修复:

func (bc *BoltClient) Seed() {
     bc.initializeBucket() 
     bc.seedAccounts()
}
英文:

initializeBucket() and seedAccounts() are methods of type BoltClient, quick fix:

func (bc *BoltClient) Seed() {
     bc.initializeBucket() 
     bc.seedAccounts()
}

huangapple
  • 本文由 发表于 2017年3月16日 17:24:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/42829900.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定