Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <vector>
- using namespace std;
- //Parent Class:
- class Displayable{
- public:
- virtual void display();
- };
- void Displayable::display(){
- cout << "OBJECT DISPLAYED\n\n";
- }
- //Subclass:
- class Player : public Displayable{
- public:
- virtual void display();
- };
- void Player::display(){
- cout << "PLAYER DISPLAYED\n\n";
- }
- //Subclass:
- class Enemy : public Displayable{
- public:
- virtual void display();
- };
- void Enemy::display(){
- cout << "ENEMY DISPLAYED\n\n";
- }
- int main(){
- vector<Displayable*> myGame;
- myGame.push_back(new Player());
- myGame.push_back(new Enemy());
- for(vector<Displayable*>::iterator iter = myGame.begin(); iter != myGame.end(); ++iter){
- (*iter)->display();
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement