Created
June 13, 2011 06:07
-
-
Save Jookia/1022374 to your computer and use it in GitHub Desktop.
Inheritence to avoid duplicating business code.
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 <ctime> | |
#include <cstdlib> | |
#include <iostream> | |
using namespace std; | |
class feline | |
{ | |
public: | |
feline(void) | |
{ | |
srand(time(0)); | |
cout << "Feline created!" << endl; | |
} | |
void entertain(void) | |
{ | |
switch(rand() % 2) | |
{ | |
case 0: | |
meow(); | |
break; | |
case 1: | |
eat(); | |
break; | |
} | |
} | |
protected: | |
virtual void meow(void) = 0; | |
virtual void eat(void) = 0; | |
}; | |
class cat | |
: public feline | |
{ | |
protected: | |
virtual void meow(void) | |
{ | |
cout << "Meow!" << endl; | |
} | |
virtual void eat(void) | |
{ | |
cout << "Nom nom nom..." << endl; | |
} | |
}; | |
int main(void) | |
{ | |
cat annoyingThing; | |
annoyingThing.entertain(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment