Last active
October 22, 2022 19:05
-
-
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?"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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