Is it possible to have an array of a 'abstract' base type and if so, how is it initialize with the least effort. The code below stops compiler with error 'type mismatch', which it actually is not, because I implicitly said that array 'myarray' and 'myarray2' is of type TAnimalArray. Also a function taking an openarray of PAnimal do not support inherited types in the array. Easiest way around this, or is it a bug? (see code below)
#Robert
type
TAnimal=object
PAnimal=ref TObject
TDog=object of TAnimal
PDog=ref TDog
TCat=object of TAnimal
PCat=ref TCat
TAnimalArray=array[0..2,PAnimal]
proc newDog():PDog = new(result)
proc newCat():PCat = new(result)
proc test(a:openarray[PAnimal])=
echo("dummy")
test(newDog(),newCat()) #does not work
var myarray:TAnimalArray=[newDog(),newCat(),newDog()] #does not work
var myarray2:TAnimalArray=[newDog(),newDog(),newDog()] #does not work either
test(PAnimal(newDog()), PAnimal(newCat()))