Created
October 23, 2017 09:31
-
-
Save vpetrigo/c145e9c7e0fd3847898cec4915d765bb to your computer and use it in GitHub Desktop.
Multiple inheritance example
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
#include <iostream> | |
struct A { | |
virtual ~A() = default; | |
}; | |
struct C { | |
virtual ~C() = default; | |
void foo() { | |
std::cout << "C: " << __func__ << std::endl; | |
} | |
}; | |
struct D : A, C { | |
virtual ~D() = default; | |
void bar() { | |
std::cout << "D: " << __func__ << std::endl; | |
} | |
}; | |
struct B : A { | |
virtual ~B() = default; | |
void baz() { | |
std::cout << "B: " << __func__ << std::endl; | |
} | |
}; | |
struct E : B, C, D { | |
virtual ~E() = default; | |
}; | |
int main() { | |
E e; | |
std::cout << sizeof e << std::endl; | |
e.baz(); | |
D &d = e; | |
d.foo(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment