Sunday 15 February 2015

go - Adding a pointer to a struct to a slice -


I am trying to add one pointer to one piece, but I can not get rid of this error I can not use NewDog (* (type * dog) * * Type * Add to animal: * The animal is the indicator for the interface, not the interface

/ Pre>

How can I avoid this error? (Still using pointers)

  package main import "fmt" type animal interface {speaking ()} type dog structure {} func (d * dog) speak () {fmt. Println ("Rough!")} Func NewDog () * Dogs {Return & Dogs} {}} Fenc Main () Pets: = Making ([] * Animals, 2) Pets [0] = New Dog () * Pets [0]) .Pak ()}    

package main Import "fmt" Type Animal Interface (Speak ()} Type Dog Structure {} Throw (Dood Dog) Functional Function (Functionality) * Functional Function (Functionality) * Functional Function () * Func NewDog () * Dog {Return & Dog {}} Function Main () {Pets: = Creating ([] Animals, 2) Pets [0] = New Dog (Pets) [0]. Speak ()}

You do not need a piece of animal interface.



No comments:

Post a Comment