duanguai2781 2018-04-27 12:45
浏览 67
已采纳

使用的变量。 但是错误仍然表明“变量x未使用” [关闭]

I am new to Golang. I am trying to clean duplicates. When I try to build the go code, I get this error.

    utils.go:60:62: cleanedTransactedFrom declared and not used

I made sure that they are used. I am sorry about the naming conventions. I am very new to Golang, so I am yet to follow the conventions. As of now consider types.TransactedFrom is a simple struct that has ID and TimeStamp.

  func removeDuplicates(TransactedFrom [][]types.TransactedFrom) [][]types.TransactedFrom {
    cleanedTransactedFrom := [][]types.TransactedFrom{}
    equal := true
    for index, singleTransactedFrom := range TransactedFrom {
      for _, selectedTransactedFrom := range TransactedFrom[index:] {
        if reflect.DeepEqual(singleTransactedFrom, selectedTransactedFrom) {
          equal = false
        }
      }
      if equal {
        cleanedTransactedFrom := append(cleanedTransactedFrom, singleTransactedFrom)
      }
      equal = true
    }
    return cleanedTransactedFrom
  }
  • 写回答

1条回答 默认 最新

  • dr2898 2018-04-27 12:48
    关注

    Change

    equal := false
    

    to

    equal = false
    

    because right now you're declaring a new variable in the inner block scope.

    Remember than := is both a declaration and an assignment (as noticed by peterSO you have the same problem for another variable and you should probably check your whole code now that you know how it works).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度