Comparison operatorsに行くプログラミング言語仕様のセクションは同等のフィールドを含む構造体が同等であることを信じるように私をリード:すべてのフィールドが同等である場合Golang構造体の比較
構造体の値は同等です。対応する非空白フィールドが等しい場合、2つの構造体の値は等しくなります。このように
「学生」構造体のフィールドのすべてが同等であるため、私は、次のコードをコンパイルする期待:
package main
type Student struct {
Name string // "String values are comparable and ordered, lexically byte-wise."
Score uint8 // "Integer values are comparable and ordered, in the usual way."
}
func main() {
alice := Student{"Alice", 98}
carol := Student{"Carol", 72}
if alice >= carol {
println("Alice >= Carol")
} else {
println("Alice < Carol")
}
}
しかし、それfails to compileメッセージを持つ:
無効な操作:alice> = carol(演算子> =構造体に定義されていません)
私は何が欠けていますか?