Created
July 12, 2012 15:42
-
-
Save Twinklebear/3098930 to your computer and use it in GitHub Desktop.
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 <string> | |
#include <iostream> | |
#include <vector> | |
class Bike{ | |
public: | |
void Peddle(){ | |
moving = true; | |
} | |
virtual void Move(){ | |
std::cout << "Bike move!" << std::endl; | |
} | |
virtual std::string Description(){ | |
return "Bike descript"; | |
} | |
protected: | |
bool moving; | |
}; | |
class RoadBike : public Bike{ | |
public: | |
void Move(){ | |
if (moving){ | |
//Move real fast! | |
} | |
} | |
std::string Description(){ | |
return "A super fast road bike!"; | |
} | |
}; | |
class MountainBike : public Bike{ | |
public: | |
void Move(){ | |
if (moving){ | |
//move kinda slow cause it's heavier | |
} | |
} | |
std::string Description(){ | |
return "A bike good for goin off-road!"; | |
} | |
}; | |
int main(){ | |
RoadBike *rbike = new RoadBike(); | |
MountainBike *mbike = new MountainBike(); | |
std::vector<Bike*> bikes; | |
bikes.push_back((Bike*)rbike); | |
bikes.push_back((Bike*)mbike); | |
for (Bike *b : bikes) | |
b->Peddle(); | |
for (Bike *b : bikes) | |
b->Move(); | |
for (Bike *b : bikes) | |
std::cout << b->Description() << std::endl; | |
Bike rbike2 = RoadBike(); | |
Bike mbike2 = MountainBike(); | |
std::vector<Bike> bikes2; | |
bikes2.push_back(rbike2); | |
bikes2.push_back(mbike2); | |
for (int i = 0; i < bikes2.size(); ++i) | |
std::cout << bikes2.at(i).Description() << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment