tcommontype.nim 484 B

123456789101112131415161718192021
  1. type
  2. TAnimal=object {.inheritable.}
  3. PAnimal=ref TAnimal
  4. TDog=object of TAnimal
  5. PDog=ref TDog
  6. TCat=object of TAnimal
  7. PCat=ref TCat
  8. TAnimalArray=array[0..2,PAnimal]
  9. proc newDog():PDog = new(result)
  10. proc newCat():PCat = new(result)
  11. proc test(a:openarray[PAnimal])=
  12. echo("dummy")
  13. #test(newDog(),newCat()) #does not work
  14. var myarray:TAnimalArray=[newDog(),newCat(),newDog()] #does not work
  15. #var myarray2:TAnimalArray=[newDog(),newDog(),newDog()] #does not work either