dqmhgz5848 2014-12-02 20:29
浏览 218
已采纳

去fmt.Println显示错误的包含

I am studying GO by using "a tour of go"
The code is doing very simple things, combine first and last together and output on screen.
The output is a hex address instead of "aaabbb" after I run the code. Could anyone can help me out? Thank you

package main

import "fmt"

type Name struct{
    first,last string
}

func (name Name) fullName() string{
    return (name.first + name.last)
}

func main(){
    v := Name{"aaa","bbb"}
    fmt.Println(v.fullName)
}
  • 写回答

2条回答 默认 最新

  • douzhuang2570 2014-12-02 20:35
    关注

    You are not calling the function fullName. you are just passing 'the pointer' to it: see this http://play.golang.org/p/GjibbfoyH0

    package main
    
    import "fmt"
    
    type Name struct {
        first, last string
    }
    
    func (name Name) fullName() string {
        return (name.first + name.last)
    }
    
    func main() {
        v := Name{"aaa", "bbb"}
        fmt.Println(v.fullName())
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求给定范围的全体素数p的(p-2)的连乘积
  • ¥15 VFP如何使用阿里TTS实现文字转语音?
  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术
  • ¥15 请问有用MZmine处理 “Waters SYNAPT G2-Si QTOF质谱仪在MSE模式下采集的非靶向数据” 的分析教程吗
  • ¥50 opencv4nodejs 如何安装
  • ¥15 adb push异常 adb: error: 1409-byte write failed: Invalid argument
  • ¥15 nginx反向代理获取ip,java获取真实ip
  • ¥15 eda:门禁系统设计
  • ¥50 如何使用js去调用vscode-js-debugger的方法去调试网页