I'm trying to make an array with objects based from the same class, but they end up being "casted". Is there any way to get around this? Example:
type Animal = ref object of RootObj
name: string
type Cat = ref object of Animal
cuteness: float
type Bird = ref object of Animal
featherColor: string
var cat = Cat(name: "Tom", cuteness: 9.4)
var bird = Bird(name: "Birb", featherColor: "red")
proc test(animal: Animal) =
echo "Generic Animal proc"
echo animal.name
proc test(animal: Cat) =
echo "Overloaded Cat proc"
echo animal.name, animal.cuteness
var animals: array[2, Animal] = [cat, bird]
test(animals[0]) # should call the Cat one, but calls the generic Animal one
This is also somewhat mentioned here, but doesn't show an actual working example: https://github.com/nim-lang/Nim/wiki/Nim-for-Python-Programmers#inheritance