Skip to content

Instantly share code, notes, and snippets.

@Jookia
Created June 13, 2011 06:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jookia/1022374 to your computer and use it in GitHub Desktop.
Save Jookia/1022374 to your computer and use it in GitHub Desktop.
Inheritence to avoid duplicating business code.
#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