Created
February 23, 2022 13:35
-
-
Save MATRIXKOO/f3814906365af7e45e4f240b8a40b0a2 to your computer and use it in GitHub Desktop.
Diamond class.
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
class X {}; | |
class Y : public virtual X {}; | |
class Z : public virtual X {}; | |
class A : public Y , public Z {}; | |
/* | |
X --> +-----------+ | |
| 1 bytes | | |
+-----------+ | |
vtable | |
+-----------------------+ | |
| 0 (top_offset) | | |
+-----------------------+ | |
Y/Z-->+----------+ | ptr typeinfo for Y/Z | | |
| vtptr |-------> +-----------------------+ | |
+----------+ | |
| pad | | |
+----------+ | |
sizeof(D) = 48,align = 8 vtable | |
+-----------------------+ | |
| 32 (vbase_offset) | | |
+-----------------------+ | |
| 0 (top_offset) | | |
+-----------------------+ | |
| ptr to typeinfo for D | | |
+----------> +-----------------------+ | |
d --> +----------+ | | B::w() | | |
| vtptr |----+ +-----------------------+ | |
+----------+ | D::y() | | |
|pad |b | +-----------------------+ | |
+----------+ | 16 (vbase_offset) | | |
| vtptr |---------+ +-----------------------+ | |
+----------+ | | -16 (top_offset) | | |
| d | c | | +-----------------------+ | |
+----------+ | | ptr to typeinfo for D | | |
| vtptr |----+ +-----> +-----------------------+ | |
+----------+ | | C::x() | | |
| pad | a | | +-----------------------+ | |
+----------+ | | 0 (vbase_offset) | | |
| +-----------------------+ | |
| | -32 (top_offset) | | |
| +-----------------------+ | |
| | ptr to typeinfo for D | | |
+----------> +-----------------------+ | |
| A::v() | | |
+-----------------------+ | |
*/ | |
int main() | |
{ | |
X x; | |
Y y; | |
Z z; | |
A a; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment