Skip to content

Instantly share code, notes, and snippets.

@false-git
Created May 20, 2016 21:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save false-git/6755af7c91ab73e76102c370a3000fbc to your computer and use it in GitHub Desktop.
Save false-git/6755af7c91ab73e76102c370a3000fbc to your computer and use it in GitHub Desktop.
#include <iostream>
class A {
public:
void method() {
std::cout << "A::method" << std::endl;
}
virtual void vmethod() {
std::cout << "A::vmethod" << std::endl;
}
};
class B {
public:
void method() {
std::cout << "B::method" << std::endl;
}
virtual void vmethod() {
std::cout << "B::vmethod" << std::endl;
}
};
class C {};
class D: public A, B, C {};
int main() {
D d;
std::cout << (A*)&d << std::endl;
std::cout << (B*)&d << std::endl;
std::cout << (C*)&d << std::endl;
((A*)&d)->A::method();
((B*)&d)->B::method();
((A*)&d)->method();
((B*)&d)->method();
((A*)&d)->A::vmethod();
((B*)&d)->B::vmethod();
((A*)&d)->vmethod();
((B*)&d)->vmethod();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment