Skip to content

Instantly share code, notes, and snippets.

@vpetrigo
Created October 23, 2017 09:31
Show Gist options
  • Save vpetrigo/c145e9c7e0fd3847898cec4915d765bb to your computer and use it in GitHub Desktop.
Save vpetrigo/c145e9c7e0fd3847898cec4915d765bb to your computer and use it in GitHub Desktop.
Multiple inheritance example
#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