doufei6456 2013-12-27 21:20
浏览 182
已采纳

如何在同一包中的另一个类中使用一个类?

I'm fairly new to Go and I'm making an a small flashcards app. My package structure is this

VocabHelper
|
-|src
--|com
---|wks
----|card
------Card.go
------Deck.go
----|main
------main.go

Deck and Card are two separate classes but they're in the same package:

Card.go

package card

type Card struct{

    Question string
    Answer string

}

Deck.go

package card

import (
    "math/rand"
)

type Deck struct{

    Cards []card.Card

}

When I try to compile the project, the compiler says undefined:card even though card is in the same package as deck. How can I use the card class in the deck class?

  • 写回答

1条回答 默认 最新

  • dqkx69935 2013-12-27 21:25
    关注

    Leave off the card. part, and it should work. They're both in the same package.

    type Deck struct{
       Cards []Card
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥15 关于超局变量获取查询的问题
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题