-
-
Save dom96/253997643d18b961f79ddc5336d9e139 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# ... | |
Vector*[T] = object | |
x*, y*: T | |
Animatable* = ref object of RootObj | |
Ball* = ref object of Animatable | |
pos*: Vector[float] | |
method clone*(anim: Animatable): Animatable {.base.} = | |
raise | |
method badclone*(anim: Animatable): Animatable {.base.} = | |
raise | |
# this makes a bad (incomplete) copy | |
method badclone*(ball: Ball): Animatable = | |
result.new | |
result.deepCopy(ball) | |
# This works | |
method clone*(ball: Ball): Animatable = | |
var ball2 = new Ball | |
ball2.deepCopy(ball) | |
result = ball2 | |
var | |
ball = Ball(pos: Vector[float](x: 111, y: 999)) | |
goodball = ball.clone | |
badball = ball.badclone | |
echo repr ball | |
echo repr goodball | |
echo repr badball |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment