@kjk1/

book pointer methods

Go

No description

fork
loading
Files
  • main.go

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.09742159016068896","path":"main.go","file":{"path":"main.go","content":{"asEncoding":{"base64":"CnBhY2thZ2UgbWFpbgoKaW1wb3J0ICJmbXQiCgovLyA6c2hvdyBzdGFydAp0eXBlIEZvbyBzdHJ1Y3QgewoJQmFyIGludAp9CgpmdW5jIChmICpGb28pIEluY3JlbWVudCgpIHsKCWYuQmFyKysKfQoKZnVuYyBtYWluKCkgewoJdmFyIGYgRm9vCgoJLy8gQ2FsbGluZyBgZi5JbmNyZW1lbnRgIGlzIGF1dG9tYXRpY2FsbHkgY2hhbmdlZCB0byBgKCZmKS5JbmNyZW1lbnRgIGJ5IHRoZSBjb21waWxlci4KCWYgPSBGb297fQoJZm10LlByaW50ZigiZi5CYXIgaXMgJWRcbiIsIGYuQmFyKQoJZi5JbmNyZW1lbnQoKQoJZm10LlByaW50ZigiZi5CYXIgaXMgJWRcbiIsIGYuQmFyKQoKCS8vIEFzIHlvdSBjYW4gc2VlLCBjYWxsaW5nIGAoJmYpLkluY3JlbWVudGAgZGlyZWN0bHkgZG9lcyB0aGUgc2FtZSB0aGluZy4KCWYgPSBGb297fQoJZm10LlByaW50ZigiZi5CYXIgaXMgJWRcbiIsIGYuQmFyKQoJKCZmKS5JbmNyZW1lbnQoKQoJZm10LlByaW50ZigiZi5CYXIgaXMgJWRcbiIsIGYuQmFyKQp9CgovLyA6c2hvdyBlbmQ="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main

import "fmt"

// :show start
type Foo struct {
	Bar int
}

func (f *Foo) Increment() {
	f.Bar++
}

func main() {
	var f Foo

	// Calling `f.Increment` is automatically changed to `(&f).Increment` by the compiler.
	f = Foo{}
	fmt.Printf("f.Bar is %d\n", f.Bar)
	f.Increment()
	fmt.Printf("f.Bar is %d\n", f.Bar)

	// As you can see, calling `(&f).Increment` directly does the same thing.
	f = Foo{}
	fmt.Printf("f.Bar is %d\n", f.Bar)
	(&f).Increment()
	fmt.Printf("f.Bar is %d\n", f.Bar)
}

// :show end