Guest User

Untitled

a guest
Nov 11th, 2016
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 0.43 KB | None | 0 0
  1. type
  2.   PBase = ref object of RootObj
  3.   POne = ref object of PBase
  4.     x: int
  5.   PTwo = ref object of POne
  6.     y: int
  7.  
  8. iterator elems(o: PBase): int =
  9.     quit "to override!"
  10.  
  11. iterator elems(o: POne): int =
  12.     yield o.x
  13.  
  14. iterator elems(o: PTwo): int =
  15.     yield o.x
  16.     yield o.y
  17.  
  18. proc printElems(o: PBase) =
  19.     for e in elems(o):
  20.         echo "E: ", e
  21.  
  22. printElems(POne(x: 100))
  23. echo "-----"
  24. printElems(PTwo(x: 1, y: 2))
Advertisement
Add Comment
Please, Sign In to add comment