dongshi6529 2017-05-05 18:13
浏览 44
已采纳

不正确的函数声明语法错误:意外的cornerFinder,期望(

I receive this error when I try to run this code: syntax error: unexpected cornerFinder, expecting (

case "-v2":
        func cornerFinder(censusData []CensusGroup) {
            if len(censusData) <= 10000{
                for i := 0; i <= 10000; i++ {
                    if (censusData.latitude > maxLat){
                        maxLat = censusData.latitude
                    }
                    if (censusData.latitude < minLat){
                        minLat = censusData.latitude
                    }
                    if (censusData.longitude > maxLong){ 
                        maxLong = censusData.longitude
                    }
                    if (censusData.longitude < minLong){
                        minLong = censusData.longitude
                    }
                }    
            }
            mid := len(data)/2
            done := make(chan bool)
            go func() {
                cornerFinder(censusData[:mid])
                done<- true
            } ()
            cornerFinder(censusData[mid:len(censusData)])
            <-done
            return
        }
        cornerFinder(censusData)

Its giving this error on the second line of the code:

func cornerFinder(censusData []CensusGroup) {

I think it something trivial that I am missing. Been stuck on it for a couple of hours. Help would be appreciated

  • 写回答

1条回答 默认 最新

  • dppfxf909679 2017-05-05 18:21
    关注

    Function declarations are only allowed at top level. Assign a function literal to a local variable instead.

        var cornerFinder func(censusData []CensusGroup)
        cornerFinder = func(censusData []CensusGroup) {
           ... function body from the question
        }
        cornerFinder(censusData)
    

    A short variable declaration is not used here because the function calls itself recursively.

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

报告相同问题?

悬赏问题

  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程