Skip to content

Instantly share code, notes, and snippets.

@l3ngli
Created October 5, 2025 11:00
Show Gist options
  • Select an option

  • Save l3ngli/3b4a22b6f415a27d4077a4848a81cda4 to your computer and use it in GitHub Desktop.

Select an option

Save l3ngli/3b4a22b6f415a27d4077a4848a81cda4 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
#include <string>
using namespace std;
__interface IFlight {
void Fly();
};
__interface IStrength {
void Strong();
};
__interface ISpeed {
void Run();
};
class SuperHero {
protected:
string name;
string race;
string side;
public:
SuperHero(string n, string r, string s) : name(n), race(r), side(s) {}
virtual void ShowInfo() {
cout << "Name: " << name << "\nRace: " << race << "\nSide: " << side << "\n";
}
string getName() const {
return name;
}
};
class Wolverine : public SuperHero, public IStrength {
public:
Wolverine() : SuperHero("Wolverine", "Mutant", "Good") {}
void Strong() {
cout << name << " tears apart his opponents with his blades\n";
}
};
class IronMan : public SuperHero, public IFlight {
public:
IronMan() : SuperHero("Tony Stark", "Human", "Good") {}
void Fly() {
cout << name << " flies using his suit\n";
}
};
class Thor : public SuperHero, public IFlight, public IStrength {
public:
Thor() : SuperHero("Thor", "God", "Good") {}
void Fly() {
cout << name << " flies with his hammer\n";
}
void Strong() {
cout << name << " uses his god powers\n";
}
};
int main() {
vector<SuperHero*> heroes;
IronMan ironman;
Thor thor;
Wolverine wolverine;
heroes.push_back(&ironman);
heroes.push_back(&thor);
heroes.push_back(&wolverine);
cout << "\n\tAll Superheroes:\n";
for (auto h : heroes)
h->ShowInfo();
cout << "\n\tHeroes Who Can Fly:\n";
for (auto h : heroes) {
IFlight* flyer = dynamic_cast<IFlight*>(h);
if (flyer) {
cout << h->getName() << ": ";
flyer->Fly();
}
}
return 0;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment