.\import.go:9: main redeclared in this block previous declaration at .\func_add.go:12

115 views
Skip to first unread message

shinobi...@gmail.com

unread,
Oct 9, 2013, 2:48:25 AM10/9/13
to golang...@googlegroups.com

Qi

unread,
Oct 9, 2013, 3:00:18 AM10/9/13
to golang...@googlegroups.com
错误提示很明白了额。。Go的一个文件夹下就是一个包,go build不指定文件的话,就把文件夹下所有文件一起编译,所以会出现main函数重定义。要单独编译的话,得 go build xxx.go


在 2013年10月9日下午2:48, <shinobi...@gmail.com>写道:

--
--
官网: http://golang-china.org/
IRC: irc.freenode.net #golang-china
@golangchina
 
---
您收到此邮件是因为您订阅了 Google 网上论坛的“Golang-China”论坛。
要退订此论坛并停止接收此论坛的电子邮件,请发送电子邮件到 golang-china...@googlegroups.com
要查看更多选项,请访问 https://groups.google.com/groups/opt_out。

shinobi...@gmail.com

unread,
Oct 9, 2013, 3:31:11 AM10/9/13
to golang...@googlegroups.com
ok,小白 明白了,谢谢! 

在 2013年10月9日星期三UTC+8下午3时00分18秒,Qi写道:

shinobi...@gmail.com

unread,
Oct 9, 2013, 5:33:32 AM10/9/13
to golang...@googlegroups.com
// map
package main

import (
    "fmt"
)

type Vertex struct {
    Lat, Long float64
}

var m map[string]Vertex

var m2 map[string]Vertex{
    "Bell Labs": {
        40.68433, -74.39967,
    },
    "Google": {
        37.42202, -122.08408,
    },
}

func main() {
    m = make(map[string]Vertex)
    m["Bell Labs"] = Vertex{
        40.68433, 74.39967,
    }
    fmt.Println(m["Bell Labs"])
    
    fmt.Println(m2)
}


D:/go/bin/go.exe build [D:/GoStudy/map]

# _/D_/GoStudy/map

.\map.go:14: syntax error: unexpected { at end of statement

错误: 进程退出代码 2.


m2 的定义哪里有错啊,为什么编译报错?


在 2013年10月9日星期三UTC+8下午3时31分11秒,shinobi...@gmail.com写道:

shinobi...@gmail.com

unread,
Oct 9, 2013, 5:35:07 AM10/9/13
to golang...@googlegroups.com
ok,小白 明白了,谢谢! 
Reply all
Reply to author
Forward
0 new messages