2 回答
TA贡献1783条经验 获得超4个赞
package main
import "fmt"
type Person struct {
name string
age int
job string
salary int
}
func test(class Person) {
// Access and print Pers1 info
fmt.Println("Name: ", class.name)
fmt.Println("Age: ", class.age)
fmt.Println("Job: ", class.job)
fmt.Println("Salary: ", class.salary)
}
func main() {
var pers1 Person
var pers2 Person
// Pers1 specification
pers1.name = "Hege"
pers1.age = 45
pers1.job = "Teacher"
pers1.salary = 6000
// Pers2 specification
test(pers1)
pers2.name = "Cecilie"
pers2.age = 24
pers2.job = "Marketing"
pers2.salary = 4500
test(pers2)
}
/* 试试这个,你必须将它作为 test(pers1) 和 test(pers2) 传递。我希望它现在能正常工作。*/
- 2 回答
- 0 关注
- 100 浏览
添加回答
举报