Skip to content

Instantly share code, notes, and snippets.

@victusfate
Created March 15, 2011 11:42
Show Gist options
  • Select an option

  • Save victusfate/870626 to your computer and use it in GitHub Desktop.

Select an option

Save victusfate/870626 to your computer and use it in GitHub Desktop.
#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