Last active
January 24, 2017 02:20
-
-
Save ALSchwalm/5a8cd4928eb8e3c1d2993a7acc0099d1 to your computer and use it in GitHub Desktop.
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
#include <iostream> | |
#include <cstdlib> | |
struct Mammal { | |
Mammal() { std::cout << "Mammal::Mammal\n"; } | |
virtual ~Mammal() {} | |
virtual void walk() { std::cout << "Mammal::walk\n"; } | |
}; | |
struct Cat : Mammal { | |
Cat() { std::cout << "Cat::Cat\n"; } | |
virtual ~Cat() {} | |
virtual void walk() { std::cout << "Cat::walk\n"; } | |
}; | |
struct Dog : Mammal { | |
Dog() { std::cout << "Dog::Dog\n"; } | |
virtual ~Dog() {} | |
virtual void walk() { std::cout << "Dog::walk\n"; } | |
}; | |
struct Bird { | |
Bird() { std::cout << "Bird::Bird\n"; } | |
virtual ~Bird() {} | |
virtual void fly() { std::cout << "Bird::fly\n"; } | |
}; | |
//NOTE: this may not be taxonomically correct | |
struct Bat : Bird, Mammal { | |
Bat() { std::cout << "Bat::Bat\n"; } | |
virtual ~Bat() {} | |
virtual void fly() { std::cout << "Bat::fly\n"; } | |
}; | |
int main() { | |
Bird *b; | |
Mammal* m; | |
if (rand() % 2) { | |
b = new Bat(); | |
m = new Cat(); | |
} else { | |
b = new Bird(); | |
m = new Dog(); | |
} | |
b->fly(); | |
m->walk(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment