Utilizzando struct
e una funzione che dovrebbe stampare gli elementi della struct, ho scritto questo semplice programma:errore: struct tipo non è espressione
package main
import "fmt"
type Salutation struct {
name string
greeting string
}
func Greet(salutation Salutation) {
fmt.Println(salutation.name)
fmt.Println(salutation.greeting)
}
func main() {
var s = Salutation
s.name = "Alex"
s.greeting = "Hi"
Greet(s)
}
quando l'eseguo ottengo l'errore go:16: type Salutation is not an expression
. Cosa va storto qui?
È interessante notare che quando cambio la definizione di s
a var s = Salutation {"Alex", "Hi"}
funziona perfettamente. Ma sono fondamentalmente diversi modi sintattici per definire la stessa entità. Ecco perché non capisco la fonte dell'errore.
'type salution struct {}' è possibile accedere a 'struct'' fmt.Println (salution, "struct typee") '@Cerise Limon – muthukumar