相关疑难解决方法(0)

转换嵌入式struct call子方法代替父方法

这里是Go代码示例,包含Interface,Parent Struct和2 Children Structs

package main

import (
    "fmt"
    "math"
)

// Shape Interface : defines methods
type ShapeInterface interface {
    Area() float64
    GetName() string
    PrintArea()
}

// Shape Struct : standard shape with an area equal to 0.0
type Shape struct {
    name string
}

func (s *Shape) Area() float64 {
    return 0.0
}

func (s *Shape) GetName() string {
    return s.name
}

func (s *Shape) PrintArea() {
    fmt.Printf("%s : Area %v\r\n", s.name, s.Area())
}

// Rectangle Struct : …
Run Code Online (Sandbox Code Playgroud)

methods struct parent-child go

4
推荐指数
1
解决办法
848
查看次数

标签 统计

go ×1

methods ×1

parent-child ×1

struct ×1