syntax error: non-declaration statement outside function body
来源:互联网 发布:阿里云yum安装mysql 编辑:程序博客网 时间:2024/05/28 22:09
刚学go,为什么这么写会报错?
- golang
package mainimport( "fmt")type person struct { name string age int}var P personP.name = "annie"P.age = 20func main() { fmt.Printf("The person's name is %s", P.name)}
报错信息:/struct.go:14: syntax error: non-declaration statement outside function body
你非得在main函数外赋值的话,要这样写
package mainimport( "fmt")type person struct { name string age int}var P =person{"annie",20}func main() { fmt.Printf("The person's name is %s", P.name)}
要不然就得这样写
package mainimport( "fmt")type person struct { name string age int}var P personfunc main() { P.name="a" P.age=10 fmt.Printf("The person's name is %s", P.name)}
阅读全文
0 0
- syntax error: non-declaration statement outside function body
- “ error: expected declaration or statement at end of input/n warning: control reaches end of non-void function”
- Android error 之 Syntax error, insert ";" to complete Local Variable Declaration Statement
- error: implicit declaration of function '********'
- symbian 的“declaration syntax error”错误
- symbian 的“declaration syntax error”错误
- error: expected declaration or statement at end
- __FUNCTION__ predefined macro cannot appear outside of a function body
- Syntax error, insert "}" to complete Class body.
- error C2899: typename cannot be used outside a template declaration
- init_MUTEX 發生 implicit declaration of function error
- error: implicit declaration of function ‘luaL_register’
- error: implicit declaration of function 'kmalloc'
- error: implicit declaration of function ‘class_device_create’
- error:implicit declaration of function "irq_to_gpio"
- error: implicit declaration of function 'xxx'
- error: implicit declaration of function 'gettimeofday'
- error:implicit declaration of function 'kmalloc'
- 结构体中运算符的重载
- setuptools 和easy_install介绍和安装方法
- Leetcode-117: Populating Next Right Pointers in Each Node II
- LuoguP1637 三元上升子序列
- HDU 1950(LIS)
- syntax error: non-declaration statement outside function body
- 关于Java中的 i = i ++ 的问题
- 聊天室
- [编程题] 头条校招
- HDU4358【离散化+DFS序+莫队算法】
- AI开发实战3-定制自己的Screen
- leetcode[Longest Harmonious Subsequence]
- 面向对象编程思想-观察者模式
- linux TCP 参数设置