Created
February 27, 2011 15:35
-
-
Save nazgob/846260 to your computer and use it in GitHub Desktop.
"classic" OO solution for birds problem
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> | |
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