There was an error while loading. Please reload this page.
The __assign__ method can be created to override the assignment = operator for struct values.
__assign__
=
func __assign__(this *T, other T) { }
or
func __assign__(this *T, other POD T) { }
where T is the struct type in question.
T
import basics struct UnorderedPair (first, second int) func __assign__(this *UnorderedPair, other POD UnorderedPair) { this.first = other.second this.second = other.first } func toString(pair UnorderedPair) String { return "(%, %)" % pair.first % pair.second } func main { pair1 UnorderedPair pair1.first = 1 pair1.second = 2 print(pair1) pair2 UnorderedPair = pair1 print(pair2) }
(1, 2) (2, 1)
Table of Contents