class包
package class
import (
"fmt"
)
type Age interface{
AgePlus()
AgeNow()
}
type Person struct {
Name string
Age int
}
func (this *Person) AgePlus() {
this.Age += 10
}
func (this Person) AgeNow() {
fmt.Println("His age is:", this.Age)
}
main包
package main
import (
"class"
)
func main() {
p := Person{Name: "Robin", Age: 20}
var robin Age
robin = p
robin.AgePlus()
robin.AgeNow()
}
编译提示错误
import and not used:"class"
undefined:Person
udefined:Age
这是为什么?
有疑问加站长微信联系(非本文作者)