Skip to content

Can not call struct method #174

Closed
Closed
@xdays

Description

@xdays

I can't run the following code

import "fmt"
type person struct{
    first string
    last string
}

func (s person) speak() {
    fmt.Println("I am", s.first, s.last)
}

p1 := person{
    first: "xdays",
    last: "chen",
}
fmt.Println(p1)
p1.speak()

and the error messge is:

repl.go:60:1: not a package: "p1" in p1.speak <*ast.SelectorExpr>

here's result from play.golang.org https://play.golang.org/p/3MUTTha849C

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions