
10

菜鸡问题: 结构体定义在函数内部如何?
source link: https://www.v2ex.com/t/796413
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

菜鸡问题: 结构体定义在函数内部如何?
语法上没有限制. 但是我在书上没见过这么用.
为什么不这样用呢?
譬如 我想解析很多个 json 但是都是一次性的. 那我得起好多个名字.
一种简便的方式是 在每个函数里面定义一个 结构体 不行吗? 这样命名空间是隔离的 结构体的名字就可以是一个了.
为什么不这样用呢?
譬如 我想解析很多个 json 但是都是一次性的. 那我得起好多个名字.
一种简便的方式是 在每个函数里面定义一个 结构体 不行吗? 这样命名空间是隔离的 结构体的名字就可以是一个了.
9 条回复 • 2021-08-18 09:05:51 +08:00
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK