golang cannot assign to
来源:互联网 发布:ipad能刷windows系统吗 编辑:程序博客网 时间:2024/06/05 16:14
问题:
# command-line-arguments
.\example.go:22: cannot assign to m.V.(BasicMessage).Length
想在函数中修改interface表示的结构体的成员变量的值,编译时遇到这个编译错误,问题代码如下:
package mainimport ( "fmt")type Message struct { V interface{}}type BasicMessage struct { Length int}func test(m *Message) { m.V.(BasicMessage).Length = 1}func main() { m := &Message{} fmt.Println("m:", m) test(m) fmt.Println("m:", m)}
原因:
interface不能使用这种赋值方式。
解决办法:
将test函数中赋值方式修改为:
func test(m *Message) { bm := BasicMessage{} bm.Length = 1 m.V = bm}
output:
m: &{<\nil>}
m: &{{1}}
阅读全文
0 0
- golang cannot assign to
- golang,redigo 使用中 Cannot assign requested address的解决办法
- Cannot assign a TFont to a TFont
- Cannot assign a TFont to a TFont!!
- cannot assign a tfont to a tfont
- Cannot assign a device to node
- delphi7 Cannot assign a TFont to a TFont问题
- DLL:cannot assign a tfont to a tfont
- [JavaScript] In Velocity, CANNOT assign null to LRS
- Cannot assign value of type 'InterfaceController' to type 'HKWorkoutSessinDelegate'
- Cannot assign value of type 'AnyObject' to type 'HereIsTheTypeName?'
- QPixmap::operator=: Cannot assign to pixmap during painting
- Cannot assign requested address
- Cannot assign requested address
- Cannot assign requested address
- Cannot assign requested address
- OPCAutomation_TLB.pas(1240): Cannot assign to a read-only property 问题解决
- 主程序调用DLL窗体 cannot assign a TFont to a TFont 问题的彻底解决方案
- bzoj3714: [PA2014]Kuglarz
- 日历界面实现(一次输出三个月)
- Caffe之具体运行流程分析
- IT求职部分网站汇总
- spring-data知识点记载
- golang cannot assign to
- HDU 1719 Friend(规律)
- iOS:tableView刷新闪烁问题解决
- Construct2 游戏进阶制作
- 常用的正则表达式大全
- 素数筛
- VS2015静态编译libcurl(C++ curl封装类)
- Django中button的处理 & ajax提交数据时不走Form组件验证
- 经历(3)随笔