Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why i can not run this sucessfully? #41374

Closed
mejyz opened this issue Sep 14, 2020 · 1 comment
Closed

why i can not run this sucessfully? #41374

mejyz opened this issue Sep 14, 2020 · 1 comment

Comments

@mejyz
Copy link

mejyz commented Sep 14, 2020

What version of Go are you using (go version)?

$ 1.15.1
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)

@davecheney
Copy link
Contributor

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.

For asking questions, see:

@golang golang locked and limited conversation to collaborators Sep 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants