Created
December 8, 2018 14:46
-
-
Save hempnall/ef652e870d9d822fc3929609b9349d86 to your computer and use it in GitHub Desktop.
C++ Multiple Inheritance (Virtual) Wierdness
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
// ConsoleApplication2.cpp : This file contains the 'main' function. Program execution begins and ends there. | |
// | |
#include <iostream> | |
#include <vector> | |
#define DEBUG( x ) std::cout << "[+] " << x << std::endl; | |
class Grandma { | |
std::vector<int> x_; | |
protected: | |
Grandma() { | |
DEBUG( "Grandma") | |
} | |
int hello() { | |
return 123; | |
}; | |
}; | |
#define VIRTUALGMA virtual | |
class Ma1 : public VIRTUALGMA Grandma { | |
public: | |
Ma1() { | |
DEBUG("Ma1") | |
} | |
std::vector<int> y_; | |
}; | |
class Ma2 : public VIRTUALGMA Grandma { | |
public: | |
Ma2() { | |
DEBUG("Ma2") | |
} | |
}; | |
#define VIRTUALME virtual | |
class Me : | |
public VIRTUALME Ma2, | |
public VIRTUALME Ma1 | |
{ | |
public: | |
void eMe() { | |
DEBUG( "Me" ) | |
} | |
}; | |
#define VIRTUALYOU virtual | |
class You : public VIRTUALYOU Me | |
{ | |
public: | |
You() : Me() { | |
DEBUG( "You") | |
} | |
}; | |
int main() | |
{ | |
std::cout << "Hello World!\n"; | |
You* m = new You; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment