Skip to content

Instantly share code, notes, and snippets.

@collinalexbell
Last active October 22, 2022 19:05
Show Gist options
  • Save collinalexbell/4bba43db3d4ff34d50b6c17e74134c48 to your computer and use it in GitHub Desktop.
Save collinalexbell/4bba43db3d4ff34d50b6c17e74134c48 to your computer and use it in GitHub Desktop.
Don't know what interfaces or pure virtual functions are. Ask yourself, "what does the generic animal say?"
/*
Someone on reddit asked is the point of pure virtual function in c++.
Here was my response
@kuberlog the [CyberRanger](https://www.youtube.com/channel/UChsxOQf3j6Jw_BbzWcsIQPg)
*/
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?
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment