Let's have a code example. When I'm using ref object of ... This code:
type
Animal = ref object of RootObj
name: string
method makeNoise(this: Animal) {.base.} =
echo "..."
type
Human = ref object of Animal
Dog = ref object of Animal
method makeNoise(this: Human) =
echo "Hi, I'm ", this.name
method makeNoise(this: Dog) =
echo "*Bark!* [said ", this.name, "]"
let
h = Human(name: "Kevin Bacon")
d = Dog(name: "Fuzzy")
h.makeNoise()
d.makeNoise()
let a:Animal = Dog(name: "Fluffy")
a.makeNoise()
Produces this result:
Hi, I'm Kevin Bacon
*Bark!* [said Fuzzy]
*Bark!* [said Fluffy]
But when we take away that ref keyword from the type lines, the output becomes
this:
Hi, I'm Kevin Bacon
*Bark!* [said Fuzzy]
...
This leads me to believe that my objects need to be reference counted to take
advantage of dynamic dispatch. Is this true?