mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 02:16:48 +08:00
fix: coding style and file format for chapter 10.
This commit is contained in:
@@ -1,25 +1,26 @@
|
||||
// methods1.go
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
/* basic data structure upon with we'll define methods */
|
||||
type employee struct {
|
||||
salary float32
|
||||
}
|
||||
|
||||
/* a method which will add a specified percent to an
|
||||
employees salary */
|
||||
func (this *employee) giveRaise(pct float32) {
|
||||
this.salary += this.salary * pct
|
||||
}
|
||||
|
||||
func main() {
|
||||
/* create an employee instance */
|
||||
var e = new(employee)
|
||||
e.salary = 100000;
|
||||
/* call our method */
|
||||
e.giveRaise(0.04)
|
||||
fmt.Printf("Employee now makes %f", e.salary)
|
||||
}
|
||||
// Employee now makes 104000.000000
|
||||
// methods1.go
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
/* basic data structure upon with we'll define methods */
|
||||
type employee struct {
|
||||
salary float32
|
||||
}
|
||||
|
||||
/* a method which will add a specified percent to an
|
||||
employees salary */
|
||||
func (this *employee) giveRaise(pct float32) {
|
||||
this.salary += this.salary * pct
|
||||
}
|
||||
|
||||
func main() {
|
||||
/* create an employee instance */
|
||||
var e = new(employee)
|
||||
e.salary = 100000
|
||||
/* call our method */
|
||||
e.giveRaise(0.04)
|
||||
fmt.Printf("Employee now makes %f", e.salary)
|
||||
}
|
||||
|
||||
// Employee now makes 104000.000000
|
||||
|
Reference in New Issue
Block a user