我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

为什么我收到非数字类型* int错误?

I am getting non-numeric type *int error in the example below, why ?

func main() {
    count := 0
    for {
        counting(&count)
    }
}

func counting(count *int) {
    fmt.Println(count)
    count++
}

You need to derefence the pointer:

package main

import (
    "fmt"
)

func main() {
    count := 0
    for i:=0; i<10; i++ {
        counting(&count)
    }
}

func counting(count *int) {
    fmt.Println(*count)
    *count++
}

近期文章

  • 每次发生突变时都会出现新对象吗?
  • angularjs $ http发布无法正常工作
  • Golang-没有选择器的软件包用户
  • 接口定义中方法签名中的接口
  • 重定向返回http:多个响应.WriteHeader调用
  • 从JSON解析对象的嵌套数组到Go
  • 具有字符串索引的多层切片
  • 导入软件包的正确项目结构
  • 前往:如何两次嵌入相同的界面?
  • 开发可访问Windows的Go应用程序
  • 当go中的form参数是map时,传入了什么?
  • 在golang中如何测试地图或通道未初始化
  • Golang中未输入频道
  • 结构中的私有/公共字段..作用不同
  • 在Go中打印数组值
  • 向浏览器发送“ null”而不是“ {}”
  • json.Unmarshal到对象的json字符串为空结果[重复]
  • Golang:对接口切片进行排序
  • 为什么频道未收到struct的成员
  • 前往:是否需要设置属性但没有指针接收器?

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华