On Mon, 23 Jan 2017 17:47:48 -0800 (PST)
hui zhang wrote:
> type IReset interface {
>Reset()
> }
> type Fight struct {
>hp,mp int
> }
[...]
> func reset1(x IReset){
>x.Reset()
> }
> func reset(x []IReset) {
>for i := range x {
> x[i].Reset()
>}
> }
> func Reset() {
>
In past answers to similar questions, I have seen the stated answers being
that []Fight and []IReset are not the same type, and there is no support
for automatically converting from one to the other, and it will not treat
the slice of concrete types as the slice of IReset interfaces because of a
di
check code below, How to use []interface{} in generic programing?
type IReset interface {
Reset()
}
type Fight struct {
hp,mp int
}
func (my *Fight) Reset () {
my.hp = 0
my.mp = 0
}
func reset1(x IReset){
x.Reset()
}
func reset(x []IReset) {
for i := range x {
x[i].Reset()