Created
December 10, 2014 23:30
-
-
Save gokr/73cb41ac285611ba047a to your computer and use it in GitHub Desktop.
Inheritance of ==?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type | |
Vehicle* = ref object of RootRef | |
color*: string | |
type | |
Car* = ref object of Vehicle | |
make*: string | |
# This method ... is never called, it seems | |
# that system.`==` is preferred, why? | |
method `==`*(self, other: Vehicle): bool = | |
echo "why can't we get here?" | |
true | |
# If we enable this method it will be used | |
#method `==`*(self, other: Car): bool = | |
# echo "this one works" | |
# true | |
var volvo = Car(color: "blue", make: "Volvo") | |
var saab = Car(color: "red", make: "Saab") | |
echo(volvo == saab) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment