What does the generic Animal say?

1 min read Original article ↗

collin

Beginner programmers on reddit seem to really struggle with the concept of interfaces or pure virtual functions. I thought up a hillarious example to show them what it is all about. I give you, Yelvis.cpp

/* Abstract class Animal and a bunch of concrete implementing classes like Dog, Cat, and Bird goes here */Vector<Animal> animals = getZoo();
for(auto it = animals.begin(); it != animals.end(); it++) {
it->vocalize()
}
/*
Prints the following:
"Dog goes woof
Cat goes meow
Bird goes tweet
Mouse goes squeek

Cow goes moo
Frog goes croak
Elephant goes toot
Ducks say quack
Fish go blub
Seal goes ow, ow, ow"

...but there is one sound that no one knows...
What does the generic Animal say?
*/