Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- __interface IMove {
- void Move();
- };
- struct Flying {
- virtual void Fly() abstract;
- virtual ~Flying() = default;
- };
- class Jumping {
- public:
- virtual void Jump() abstract;
- virtual ~Jumping() = default;
- };
- struct FootMove : IMove {
- virtual void Step() abstract;
- virtual ~FootMove() = default;
- };
- class Human : FootMove, Jumping, Flying {
- protected:
- string name;
- public:
- Human() = delete;
- Human(string name) : name(name) {}
- virtual ~Human() = default;
- };
- struct Func {
- static void MakeMove(IMove* move) {
- move->Move();
- }
- };
- class Lena : Human {
- Lena() : Human("Lena") {}
- public:
- static Lena* Initialize() {
- return new Lena();
- }
- void Move() override {
- this->Step();
- }
- void Jump() override {
- cout << "JumP" << endl;
- }
- void Fly() override {
- cout << "I believe, I can fly..." << endl;
- }
- private:
- void Step() override {
- cout << "Step!" << endl;
- }
- };
- int main(void) {
- FootMove whynot;
- whynot.Step();
- Lena first;
- first.Move();
- first.Fly();
- Lena* second = Lena::Initialize();
- second->Move();
- second->Fly();
- Func::MakeMove((IMove*)(FootMove*)(Human*)second);
- system("pause > NUL");
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement