no new variables on left side of

25 views
Skip to first unread message

dragonwei

unread,
Oct 24, 2012, 10:37:04 PM10/24/12
to golang...@googlegroups.com
  9 func parseComm(comm []string)(srcIP string, srcPort string, destIp string, destPort string, state string){
 10                 source := comm[1]
 11                 dest := comm[2]
 12                 state := comm[3] //状态机状态,0A LISTEN, 01 ESTABLISHED
 13                 srcIp := source[:8]
 14                 srcPort := source[9:]
 15                 destIp := dest[:8]
 16                 destPort := dest[9:]
 17 
 18                 return srcIp,srcPort,destIp,destPort,state
 19 }

编译的时候怎么出现:
./typo.go:12: no new variables on left side of :=
./typo.go:14: no new variables on left side of :=
./typo.go:15: no new variables on left side of :=
./typo.go:16: no new variables on left side of :=

dragonwei

unread,
Oct 24, 2012, 10:44:07 PM10/24/12
to golang...@googlegroups.com
因为没有初始化?

Ruiqi Hong

unread,
Oct 24, 2012, 10:45:03 PM10/24/12
to golang...@googlegroups.com
去掉冒号,返回值有名字相当于定义了这个变量

2012/10/25 dragonwei <ipv6...@gmail.com>

--
官网: http://golang-china.org/
IRC: irc.freenode.net #golang-china
@golangchina

Wendal Chen

unread,
Oct 24, 2012, 10:45:18 PM10/24/12
to golang...@googlegroups.com
你的方法声明已经带参数名了

2012/10/25 dragonwei <ipv6...@gmail.com>

--
官网: http://golang-china.org/
IRC: irc.freenode.net #golang-china
@golangchina



--
Wendal Chen
GuangDong China

Harry Hao

unread,
Oct 24, 2012, 10:46:35 PM10/24/12
to golang...@googlegroups.com
因为那几行的左边的变量名字已经存在于参数列表中了。

2012/10/25 dragonwei <ipv6...@gmail.com>
Reply all
Reply to author
Forward
0 new messages