Files
the-way-to-go_ZH_CN/eBook/exercises/chapter_10/employee_salary.go
2015-03-03 12:25:25 -05:00

25 lines
622 B
Go
Executable File

// 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