第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

將 golang 中的指針值 *a = *b 替換為接口

將 golang 中的指針值 *a = *b 替換為接口

Go
蕪湖不蕪 2021-09-27 20:34:38
對(duì)于兩個(gè)相同類(lèi)型的變量,可以使用 *a = *b 替換指針值package mainimport (    "log")type s1 struct {    id int}func (s *s1) replace(s2 *s1) {    *s = *s2}func test(s *s1, s2 *s1) {    s.replace(s2)}func main() {    s := &s1{1}    s2 := &s1{2}    log.Println(s, s2)    test(s, s2)    log.Println(s, s2)}結(jié)果是2015/04/09 16:57:00 &{1} &{2}2015/04/09 16:57:00 &{2} &{2}對(duì)于不同類(lèi)型但相同接口的兩個(gè)變量,是否可以實(shí)現(xiàn)相同的目標(biāo)?package mainimport (    "log")type i interface {    replace(s2 i)}type s1 struct {    id int}func (s *s1) replace(s2 i) {    *s = *s2}type s2 struct {    id float64}func (s *s2) replace(s2 i) {    *s = *s2}func test(s i, s2 i) {    s.replace(s2)}func main() {    s := &s1{1}    s2 := &s2{2.0}    log.Println(s, s2)    test(s, s2)    log.Println(s, s2)}這不編譯./test.go:16: invalid indirect of s2 (type i)./test.go:24: invalid indirect of s2 (type i)
查看完整描述

2 回答

  • 2 回答
  • 0 關(guān)注
  • 281 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)