Skip to content

Instantly share code, notes, and snippets.

@nazgob
Created February 27, 2011 15:35
Show Gist options
  • Save nazgob/846260 to your computer and use it in GitHub Desktop.
Save nazgob/846260 to your computer and use it in GitHub Desktop.
"classic" OO solution for birds problem
#include <iostream>
class Bird
{
public:
virtual void Fly() const = 0;
virtual void Speak() const = 0;
};
class Eagle : public Bird
{
public:
virtual void Fly() const
{
std::cout << "Eagle shall fly now!" << std::endl;
}
virtual void Speak() const
{
std::cout << "Eagle speaking!" << std::endl;
}
};
class Penguin : public Bird
{
public:
virtual void Fly() const
{
std::cout << "Penguin shall fly now!" << std::endl;
}
virtual void Speak() const
{
std::cout << "Penquin speaking!" << std::endl;
}
};
int main()
{
std::cout << "..." << std::endl;
Bird* bird = NULL;
bird = new Eagle();
bird->Fly();
bird->Speak();
delete bird; bird = NULL;
bird = new Penguin();
bird->Fly();
bird->Speak();
delete bird; bird = NULL;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment