You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"fmt"
)
type Student struct {
Name string
Age int
Id int
}
//定义一个小学生
type Pupil struct{
Student
Score int
}
//定义一个大学生
type Graduate struct{
Student
SixScore float32
}
func Say(stu *Student) string{
infostr := fmt.Sprintf("%v说:我饿了!",(*stu).Name)
return infostr
}
func test(p *Pupil) int {
return (*p).Score +1
}
func pass(g *Graduate) float32{
return (*g).SixScore*7.10
}
func main() {
p := &Pupil{}
p.Student.Name ="小明"
p.Student.Age =8
p.Student.Id =5120130566
p.Score = 60
p.Student.Say()
result := p.test()
fmt.Printf("%v的真实成绩是%v",p.Name,p.Score)
g := &Graduate{}
g.Student.Name ="xiaohong"
g.Student.Age =26
g.Student.Id =117020910147
g.SixScore=73.2
g.Student.Say()
result1 :=g.pass()
fmt.Printf("%v的六级成绩是%v",g.Name,g.SixScore)
}
my result:
.\main.go:41:11: p.Student.Say undefined (type Student has no field or method Say)
.\main.go:42:13: p.test undefined (type *Pupil has no field or method test)
.\main.go:50:11: g.Student.Say undefined (type Student has no field or method Say)
.\main.go:51:13: g.pass undefined (type *Graduate has no field or method pass)
The text was updated successfully, but these errors were encountered:
Thank you for raising this issue. Unlike many projects, the Go project does not use GitHub Issues for general discussion or asking questions. GitHub Issues are used for tracking bugs and proposals only.
What version of Go are you using (
go version
)?my result:
The text was updated successfully, but these errors were encountered: