tmember_forward_declaration.nim 429 B

12345678910111213141516171819202122232425262728
  1. discard """
  2. targets: "cpp"
  3. cmd: "nim cpp $file"
  4. output: '''
  5. abc called
  6. def called
  7. abc called
  8. '''
  9. """
  10. type Foo = object
  11. proc abc(this: Foo, x: int): void {.member: "$1('2 #2)".}
  12. proc def(this: Foo, y: int): void {.virtual: "$1('2 #2)".}
  13. proc abc(this: Foo, x: int): void =
  14. echo "abc called"
  15. if x > 0:
  16. this.def(x - 1)
  17. proc def(this: Foo, y: int): void =
  18. echo "def called"
  19. this.abc(y)
  20. var x = Foo()
  21. x.abc(1)