Created
March 15, 2011 11:42
-
-
Save victusfate/870626 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <string> | |
| using namespace std; | |
| class Vehicle | |
| { | |
| public: | |
| Vehicle(const string& name) : name(name) {} | |
| virtual string move() = 0; | |
| const string name; | |
| }; | |
| class Car : public Vehicle | |
| { | |
| public: | |
| Car(const string& name) : Vehicle(name) {} | |
| virtual string move() { return "Vroom"; } | |
| }; | |
| class Bus : public Vehicle | |
| { | |
| public: | |
| Bus(const string& name) : Vehicle(name) {} | |
| virtual string move() { return "Putput"; } | |
| }; | |
| int main() | |
| { | |
| Vehicle* foo[] = | |
| { | |
| new Car("Kit"), | |
| new Car("Herby"), | |
| new Bus("StartupBus") | |
| }; | |
| for(int i = 0; i < 3; i++) | |
| { | |
| cout << foo[i]->name << ": " << foo[i]->move() << endl; | |
| delete foo[i]; | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment