{"id":295494,"date":"2019-12-17T16:17:29","date_gmt":"2019-12-17T16:17:29","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=295494"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=295494","title":{"rendered":"C++ vtables. \u0427\u0430\u0441\u0442\u044c 2 (Virtual Inheritance + Compiler-Generated Code)"},"content":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/480610\/\">\n<p><em>\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432 \u043a\u0443\u0440\u0441\u0430 <a href=\"https:\/\/otus.pw\/HhBg\/\">\u00ab\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0421++\u00bb<\/a>. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438? \u0421\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0437\u0430\u043f\u0438\u0441\u044c \u043c\u0430\u0441\u0442\u0435\u0440-\u043a\u043b\u0430\u0441\u0441\u0430 <a href=\"https:\/\/otus.pw\/B2p1\/\">\u00ab\u041f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Google Test Framework\u00bb<\/a>!<\/em><\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/tk\/dp\/8n\/tkdp8nfahc7sglqks8sl_tazk1o.png\"><\/p>\n<p>  <\/p>\n<h2 id=\"chast-3---virtualnoe-nasledovanie\">\u0427\u0430\u0441\u0442\u044c 3 \u2014 \u0412\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u0412 <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/479802\/\">\u043f\u0435\u0440\u0432\u043e\u0439 \u0438 \u0432\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u0438<\/a> \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a vtables \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0432 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445, \u0430 \u0437\u0430\u0442\u0435\u043c \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0438. \u0412\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u0435\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0435.<a name=\"habracut\"><\/a><\/p>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u044b, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u043e\u043c\u043d\u0438\u0442\u0435, \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u0438\u043d \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">class ios ... class istream : virtual public ios ... class ostream : virtual public ios ... class iostream : public istream, public ostream<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0431\u044b \u043d\u0435 \u043a\u043b\u044e\u0447\u0435\u0432\u043e\u0435 \u0441\u043b\u043e\u0432\u043e <code>virtual<\/code>, \u0443\u043a\u0430\u0437\u0430\u043d\u043d\u043e\u0435 \u0432\u044b\u0448\u0435, <code>iostream<\/code> \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u043c\u0435\u043b \u0431\u044b \u0434\u0432\u0430 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 <code>ios<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0433\u043e\u043b\u043e\u0432\u043d\u044b\u0435 \u0431\u043e\u043b\u0438 \u043f\u0440\u0438 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u043f\u0440\u043e\u0441\u0442\u043e \u0431\u044b\u043b\u0438 \u0431\u044b \u043d\u0435\u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u043c\u0438.<\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043d\u044f\u0442\u044c \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435, \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">#include &lt;iostream&gt; using namespace std;  class Grandparent {  public:   virtual void grandparent_foo() {}   int grandparent_data; };  class Parent1 : virtual public Grandparent {  public:   virtual void parent1_foo() {}   int parent1_data; };  class Parent2 : virtual public Grandparent {  public:   virtual void parent2_foo() {}   int parent2_data; };  class Child : public Parent1, public Parent2 {  public:   virtual void child_foo() {}   int child_data; };  int main() {   Child child; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0441\u0441\u043b\u0435\u0434\u0443\u0435\u043c <code>child<\/code>. \u042f \u043d\u0430\u0447\u043d\u0443 \u0441 \u0434\u0430\u043c\u043f\u0438\u043d\u0433\u0430 \u0431\u043e\u043b\u044c\u0448\u043e\u0433\u043e \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0430 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043c, \u0433\u0434\u0435 \u043d\u0430\u0447\u0438\u043d\u0430\u0435\u0442\u0441\u044f <code>vtable Child<\/code>, \u043a\u0430\u043a \u043c\u044b \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u043b\u0438 \u0432 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0438\u0445 \u0447\u0430\u0441\u0442\u044f\u0445, \u0430 \u0437\u0430\u0442\u0435\u043c \u043f\u0440\u043e\u0430\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b. \u042f \u043f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u0431\u044b\u0441\u0442\u0440\u043e \u0432\u0437\u0433\u043b\u044f\u043d\u0443\u0442\u044c \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0437\u0434\u0435\u0441\u044c \u0438 \u0432\u0435\u0440\u043d\u0443\u0442\u044c\u0441\u044f \u043a \u043d\u0435\u043c\u0443, \u043a\u043e\u0433\u0434\u0430 \u044f \u0440\u0430\u0441\u043a\u0440\u043e\u044e \u0434\u0435\u0442\u0430\u043b\u0438 \u043d\u0438\u0436\u0435.<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">(gdb) p child $1 = {&lt;Parent1&gt; = {&lt;Grandparent&gt; = {_vptr$Grandparent = 0x400998 &lt;vtable for Child+96&gt;, grandparent_data = 0}, _vptr$Parent1 = 0x400950 &lt;vtable for Child+24&gt;, parent1_data = 0}, &lt;Parent2&gt; = {_vptr$Parent2 = 0x400978 &lt;vtable for Child+64&gt;, parent2_data = 4195888}, child_data = 0} (gdb) x\/600xb 0x400938 0x400938 &lt;vtable for Child&gt;:    0x20    0x00    0x00    0x00    0x00    0x00    0x00    0x00 0x400940 &lt;vtable for Child+8&gt;:  0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00 0x400948 &lt;vtable for Child+16&gt;: 0x00    0x0b    0x40    0x00    0x00    0x00    0x00    0x00 0x400950 &lt;vtable for Child+24&gt;: 0x70    0x08    0x40    0x00    0x00    0x00    0x00    0x00 0x400958 &lt;vtable for Child+32&gt;: 0xa0    0x08    0x40    0x00    0x00    0x00    0x00    0x00 0x400960 &lt;vtable for Child+40&gt;: 0x10    0x00    0x00    0x00    0x00    0x00    0x00    0x00 0x400968 &lt;vtable for Child+48&gt;: 0xf0    0xff    0xff    0xff    0xff    0xff    0xff    0xff 0x400970 &lt;vtable for Child+56&gt;: 0x00    0x0b    0x40    0x00    0x00    0x00    0x00    0x00 0x400978 &lt;vtable for Child+64&gt;: 0x90    0x08    0x40    0x00    0x00    0x00    0x00    0x00 0x400980 &lt;vtable for Child+72&gt;: 0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00 0x400988 &lt;vtable for Child+80&gt;: 0xe0    0xff    0xff    0xff    0xff    0xff    0xff    0xff 0x400990 &lt;vtable for Child+88&gt;: 0x00    0x0b    0x40    0x00    0x00    0x00    0x00    0x00 0x400998 &lt;vtable for Child+96&gt;: 0x80    0x08    0x40    0x00    0x00    0x00    0x00    0x00 0x4009a0 &lt;VTT for Child&gt;:   0x50    0x09    0x40    0x00    0x00    0x00    0x00    0x00 0x4009a8 &lt;VTT for Child+8&gt;: 0xf8    0x09    0x40    0x00    0x00    0x00    0x00    0x00 0x4009b0 &lt;VTT for Child+16&gt;:    0x18    0x0a    0x40    0x00    0x00    0x00    0x00    0x00 0x4009b8 &lt;VTT for Child+24&gt;:    0x98    0x0a    0x40    0x00    0x00    0x00    0x00    0x00 0x4009c0 &lt;VTT for Child+32&gt;:    0xb8    0x0a    0x40    0x00    0x00    0x00    0x00    0x00 0x4009c8 &lt;VTT for Child+40&gt;:    0x98    0x09    0x40    0x00    0x00    0x00    0x00    0x00 0x4009d0 &lt;VTT for Child+48&gt;:    0x78    0x09    0x40    0x00    0x00    0x00    0x00    0x00 0x4009d8:   0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00 0x4009e0 &lt;construction vtable for Parent1-in-Child&gt;:    0x20    0x00    0x00    0x00    0x00    0x00    0x00    0x00 0x4009e8 &lt;construction vtable for Parent1-in-Child+8&gt;:  0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00 0x4009f0 &lt;construction vtable for Parent1-in-Child+16&gt;: 0x50    0x0a    0x40    0x00    0x00    0x00    0x00    0x00 0x4009f8 &lt;construction vtable for Parent1-in-Child+24&gt;: 0x70    0x08    0x40    0x00    0x00    0x00    0x00    0x00 0x400a00 &lt;construction vtable for Parent1-in-Child+32&gt;: 0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00 0x400a08 &lt;construction vtable for Parent1-in-Child+40&gt;: 0xe0    0xff    0xff    0xff    0xff    0xff    0xff    0xff 0x400a10 &lt;construction vtable for Parent1-in-Child+48&gt;: 0x50    0x0a    0x40    0x00    0x00    0x00    0x00    0x00 0x400a18 &lt;construction vtable for Parent1-in-Child+56&gt;: 0x80    0x08    0x40    0x00    0x00    0x00    0x00    0x00 0x400a20 &lt;typeinfo name for Parent1&gt;:   0x37    0x50    0x61    0x72    0x65    0x6e    0x74    0x31 0x400a28 &lt;typeinfo name for Parent1+8&gt;: 0x00    0x31    0x31    0x47    0x72    0x61    0x6e    0x64 0x400a30 &lt;typeinfo name for Grandparent+7&gt;: 0x70    0x61    0x72    0x65    0x6e    0x74    0x00    0x00 0x400a38 &lt;typeinfo for Grandparent&gt;:    0x50    0x10    0x60    0x00    0x00    0x00    0x00    0x00 0x400a40 &lt;typeinfo for Grandparent+8&gt;:  0x29    0x0a    0x40    0x00    0x00    0x00    0x00    0x00 0x400a48:   0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00 0x400a50 &lt;typeinfo for Parent1&gt;:    0xa0    0x10    0x60    0x00    0x00    0x00    0x00    0x00 0x400a58 &lt;typeinfo for Parent1+8&gt;:  0x20    0x0a    0x40    0x00    0x00    0x00    0x00    0x00 0x400a60 &lt;typeinfo for Parent1+16&gt;: 0x00    0x00    0x00    0x00    0x01    0x00    0x00    0x00 0x400a68 &lt;typeinfo for Parent1+24&gt;: 0x38    0x0a    0x40    0x00    0x00    0x00    0x00    0x00 0x400a70 &lt;typeinfo for Parent1+32&gt;: 0x03    0xe8    0xff    0xff    0xff    0xff    0xff    0xff 0x400a78:   0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00 0x400a80 &lt;construction vtable for Parent2-in-Child&gt;:    0x10    0x00    0x00    0x00    0x00    0x00    0x00    0x00 0x400a88 &lt;construction vtable for Parent2-in-Child+8&gt;:  0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00 0x400a90 &lt;construction vtable for Parent2-in-Child+16&gt;: 0xd0    0x0a    0x40    0x00    0x00    0x00    0x00    0x00 0x400a98 &lt;construction vtable for Parent2-in-Child+24&gt;: 0x90    0x08    0x40    0x00    0x00    0x00    0x00    0x00 0x400aa0 &lt;construction vtable for Parent2-in-Child+32&gt;: 0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00 0x400aa8 &lt;construction vtable for Parent2-in-Child+40&gt;: 0xf0    0xff    0xff    0xff    0xff    0xff    0xff    0xff 0x400ab0 &lt;construction vtable for Parent2-in-Child+48&gt;: 0xd0    0x0a    0x40    0x00    0x00    0x00    0x00    0x00 0x400ab8 &lt;construction vtable for Parent2-in-Child+56&gt;: 0x80    0x08    0x40    0x00    0x00    0x00    0x00    0x00 0x400ac0 &lt;typeinfo name for Parent2&gt;:   0x37    0x50    0x61    0x72    0x65    0x6e    0x74    0x32 0x400ac8 &lt;typeinfo name for Parent2+8&gt;: 0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00 0x400ad0 &lt;typeinfo for Parent2&gt;:    0xa0    0x10    0x60    0x00    0x00    0x00    0x00    0x00 0x400ad8 &lt;typeinfo for Parent2+8&gt;:  0xc0    0x0a    0x40    0x00    0x00    0x00    0x00    0x00 0x400ae0 &lt;typeinfo for Parent2+16&gt;: 0x00    0x00    0x00    0x00    0x01    0x00    0x00    0x00 0x400ae8 &lt;typeinfo for Parent2+24&gt;: 0x38    0x0a    0x40    0x00    0x00    0x00    0x00    0x00 0x400af0 &lt;typeinfo for Parent2+32&gt;: 0x03    0xe8    0xff    0xff    0xff    0xff    0xff    0xff 0x400af8 &lt;typeinfo name for Child&gt;: 0x35    0x43    0x68    0x69    0x6c    0x64    0x00    0x00 0x400b00 &lt;typeinfo for Child&gt;:  0xa0    0x10    0x60    0x00    0x00    0x00    0x00    0x00 0x400b08 &lt;typeinfo for Child+8&gt;:    0xf8    0x0a    0x40    0x00    0x00    0x00    0x00    0x00 0x400b10 &lt;typeinfo for Child+16&gt;:   0x02    0x00    0x00    0x00    0x02    0x00    0x00    0x00 0x400b18 &lt;typeinfo for Child+24&gt;:   0x50    0x0a    0x40    0x00    0x00    0x00    0x00    0x00 0x400b20 &lt;typeinfo for Child+32&gt;:   0x02    0x00    0x00    0x00    0x00    0x00    0x00    0x00 0x400b28 &lt;typeinfo for Child+40&gt;:   0xd0    0x0a    0x40    0x00    0x00    0x00    0x00    0x00 0x400b30 &lt;typeinfo for Child+48&gt;:   0x02    0x10    0x00    0x00    0x00    0x00    0x00    0x00 0x400b38 &lt;vtable for Grandparent&gt;:  0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00 0x400b40 &lt;vtable for Grandparent+8&gt;:    0x38    0x0a    0x40    0x00    0x00    0x00    0x00    0x00 0x400b48 &lt;vtable for Grandparent+16&gt;:   0x80    0x08    0x40    0x00    0x00    0x00    0x00    0x00<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u0430\u0443, \u0437\u0434\u0435\u0441\u044c \u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u0421\u0440\u0430\u0437\u0443 \u0436\u0435 \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u044e\u0442 \u0434\u0432\u0430 \u043d\u043e\u0432\u044b\u0445 \u0432\u043e\u043f\u0440\u043e\u0441\u0430: \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 <code>VTT<\/code> \u0438 \u0447\u0442\u043e \u0442\u0430\u043a\u043e\u0435 construction <code>vtable for X-in-Child<\/code>? \u041c\u044b \u043e\u0442\u0432\u0435\u0442\u0438\u043c \u043d\u0430 \u043d\u0438\u0445 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0441\u043a\u043e\u0440\u043e.<br \/>  \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c \u0441\u043e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043f\u0430\u043c\u044f\u0442\u0438 <code>Child<\/code>:<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u0420\u0430\u0437\u043c\u0435\u0440<\/th>\n<th>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>8 \u0431\u0430\u0439\u0442<\/td>\n<td>_vptr$Parent1<\/td>\n<\/tr>\n<tr>\n<td>4 \u0431\u0430\u0439\u0442\u0430<\/td>\n<td>parent1_data (+ 4 \u0431\u0430\u0439\u0442\u0430 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f)<\/td>\n<\/tr>\n<tr>\n<td>8 \u0431\u0430\u0439\u0442<\/td>\n<td>_vptr$Parent2<\/td>\n<\/tr>\n<tr>\n<td>4 \u0431\u0430\u0439\u0442\u0430<\/td>\n<td>parent2_data<\/td>\n<\/tr>\n<tr>\n<td>4 \u0431\u0430\u0439\u0442\u0430<\/td>\n<td>child_data<\/td>\n<\/tr>\n<tr>\n<td>8 \u0431\u0430\u0439\u0442<\/td>\n<td>_vptr$Grandparent<\/td>\n<\/tr>\n<tr>\n<td>4 \u0431\u0430\u0439\u0442\u0430<\/td>\n<td>grandparent_data (+ 4 \u0431\u0430\u0439\u0442\u0430 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u0414\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0443 <code>Child<\/code> \u0435\u0441\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e 1 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 Grandparent. \u041d\u0435\u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u0430\u044f \u0432\u0435\u0449\u044c \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u043d \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0439 \u0432 \u043f\u0430\u043c\u044f\u0442\u0438, \u0445\u043e\u0442\u044f \u043e\u043d \u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432\u044b\u0441\u0448\u0438\u043c \u0432 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438.<br \/>  \u0412\u043e\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <code>vtable<\/code>:<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u0410\u0434\u0440\u0435\u0441<\/th>\n<th>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/th>\n<th>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>0x400938<\/td>\n<td>0x20 (32)<\/td>\n<td>virtual-base offset (\u043c\u044b \u0441\u043a\u043e\u0440\u043e \u044d\u0442\u043e \u043e\u0431\u0441\u0443\u0434\u0438\u043c)<\/td>\n<\/tr>\n<tr>\n<td>0x400940<\/td>\n<td>0<\/td>\n<td>top_offset<\/td>\n<\/tr>\n<tr>\n<td>0x400948<\/td>\n<td>0x400b00<\/td>\n<td>typeinfo for Child<\/td>\n<\/tr>\n<tr>\n<td>0x400950<\/td>\n<td>0x400870<\/td>\n<td>Parent1::parent1_foo(). \u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c vtable Parent1 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u044e\u0434\u0430.<\/td>\n<\/tr>\n<tr>\n<td>0x400958<\/td>\n<td>0x4008a0<\/td>\n<td>Child::child_foo()<\/td>\n<\/tr>\n<tr>\n<td>0x400960<\/td>\n<td>0x10 (16)<\/td>\n<td>virtual-base offset<\/td>\n<\/tr>\n<tr>\n<td>0x400968<\/td>\n<td>-16<\/td>\n<td>top_offset<\/td>\n<\/tr>\n<tr>\n<td>0x4009<\/td>\n<td>0x400b<\/td>\n<td>typeinfo for Child<\/td>\n<\/tr>\n<tr>\n<td>70<\/td>\n<td>00<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>0x400978<\/td>\n<td>0x400890<\/td>\n<td>Parent2::parent2_foo(). \u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c vtable Parent2 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u044e\u0434\u0430.<\/td>\n<\/tr>\n<tr>\n<td>0x400980<\/td>\n<td>0<\/td>\n<td>virtual-base offset<\/td>\n<\/tr>\n<tr>\n<td>0x400988<\/td>\n<td>-32<\/td>\n<td>top_offset<\/td>\n<\/tr>\n<tr>\n<td>0x400990<\/td>\n<td>0x400b00<\/td>\n<td>typeinfo for Child<\/td>\n<\/tr>\n<tr>\n<td>0x400998<\/td>\n<td>0x400880<\/td>\n<td>Grandparent::grandparent_foo(). \u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c vtable Grandparent \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u044e\u0434\u0430.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u0412\u044b\u0448\u0435 \u043f\u043e\u044f\u0432\u0438\u043b\u0430\u0441\u044c \u043d\u043e\u0432\u0430\u044f \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044f \u2014 <code>virtual-base offset<\/code>. \u0421\u043a\u043e\u0440\u043e \u043c\u044b \u043f\u043e\u0439\u043c\u0435\u043c, \u0447\u0442\u043e \u043e\u043d \u0442\u0430\u043c \u0434\u0435\u043b\u0430\u0435\u0442.<br \/>  \u0414\u0430\u043b\u0435\u0435 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0441\u0441\u043b\u0435\u0434\u0443\u0435\u043c \u044d\u0442\u0438 \u0441\u0442\u0440\u0430\u043d\u043d\u043e \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0449\u0438\u0435 <code>construction vtables<\/code>. \u0412\u043e\u0442 construction <code>vtable for Parent1-in-Child<\/code>:<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/th>\n<th>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>0x20 (32)<\/td>\n<td>virtual-base offset<\/td>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>top-offset<\/td>\n<\/tr>\n<tr>\n<td>0x400a50<\/td>\n<td>typeinfo for Parent1<\/td>\n<\/tr>\n<tr>\n<td>0x400870<\/td>\n<td>Parent1::parent1_foo()<\/td>\n<\/tr>\n<tr>\n<td>0<\/td>\n<td>virtual-base offset<\/td>\n<\/tr>\n<tr>\n<td>-32<\/td>\n<td>top-offset<\/td>\n<\/tr>\n<tr>\n<td>0x400a50<\/td>\n<td>typeinfo for Parent1<\/td>\n<\/tr>\n<tr>\n<td>0x400880<\/td>\n<td>Grandparent::grandparent_foo()<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u041d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u044f \u0434\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u043d\u0435\u0436\u0435\u043b\u0438 \u043d\u0430\u0432\u0430\u043b\u0438\u0432\u0430\u0442\u044c \u043d\u0430 \u0432\u0430\u0441 \u0431\u043e\u043b\u044c\u0448\u0435 \u0442\u0430\u0431\u043b\u0438\u0446 \u0441\u043e \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u044b\u043c\u0438 \u0447\u0438\u0441\u043b\u0430\u043c\u0438. \u0418\u0442\u0430\u043a:<\/p>\n<p>  <\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u0432\u044b <code>Child<\/code>. \u0412\u0430\u0441 \u043f\u0440\u043e\u0441\u044f\u0442 \u0441\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0435\u0431\u044f \u0432 \u043d\u043e\u0432\u043e\u043c \u0443\u0447\u0430\u0441\u0442\u043a\u0435 \u043f\u0430\u043c\u044f\u0442\u0438. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432\u044b \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0435 <code>Grandparent<\/code> \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e (\u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435), \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u0435\u0433\u043e \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 (\u0435\u0441\u043b\u0438 \u0431\u044b \u044d\u0442\u043e \u043d\u0435 \u0431\u044b\u043b\u043e \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435, \u0432\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u043b\u0438 \u0431\u044b \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 <code>Parent1<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u0432\u044b\u0437\u0432\u0430\u043b \u0431\u044b \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 <code>Grandparent<\/code>). \u0412\u044b \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442\u0435 <code>this += 32<\/code> \u0431\u0430\u0439\u0442\u0430, \u0442\u0430\u043a \u043a\u0430\u043a \u0438\u043c\u0435\u043d\u043d\u043e \u0437\u0434\u0435\u0441\u044c \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 <code>Grandparent<\/code>, \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440. \u041e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e.<\/p>\n<p>  <\/p>\n<p>\u0417\u0430\u0442\u0435\u043c \u043d\u0430\u0441\u0442\u0443\u043f\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u044f \u0441\u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u0442\u044c <code>Parent1<\/code>. <code>Parent1<\/code> \u043c\u043e\u0436\u0435\u0442 \u0441 \u0443\u0432\u0435\u0440\u0435\u043d\u043d\u043e\u0441\u0442\u044c\u044e \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c, \u0447\u0442\u043e \u043a \u0442\u043e\u043c\u0443 \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043a\u043e\u0433\u0434\u0430 \u043e\u043d \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u0443\u0435\u0442 \u0441\u0435\u0431\u044f, <code>Grandparent<\/code> \u0443\u0436\u0435 \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d \u043c\u043e\u0436\u0435\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c <code>Grandparent<\/code>. \u041d\u043e \u043f\u043e\u0434\u043e\u0436\u0434\u0438\u0442\u0435, \u043a\u0430\u043a \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u0437\u043d\u0430\u0442\u044c, \u0433\u0434\u0435 \u043d\u0430\u0439\u0442\u0438 \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435? \u041e\u043d\u0438 \u0432\u0435\u0434\u044c \u043d\u0435 \u0432 \u043e\u0434\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435 \u0441 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u043c\u0438 <code>Parent1<\/code>!<\/p>\n<p>  <\/p>\n<p>\u041d\u0430 \u0441\u0446\u0435\u043d\u0443 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 <code>construction table for Parent1-in-Child<\/code>. \u042d\u0442\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043f\u0440\u0435\u0434\u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0430 \u0434\u043b\u044f \u0443\u043a\u0430\u0437\u0430\u043d\u0438\u044f <code>Parent1<\/code>, \u0433\u0434\u0435 \u043d\u0430\u0439\u0442\u0438 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b \u0434\u0430\u043d\u043d\u044b\u0445, \u043a \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u043d \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f. <code>this<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 <code>Parent1<\/code>. <code>virtual-base offset<\/code> \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0433\u0434\u0435 \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0439\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 Grandparent: \u041f\u0435\u0440\u0435\u0448\u0430\u0433\u043d\u0438\u0442\u0435 \u043d\u0430 32 \u0431\u0430\u0439\u0442\u0430 \u0432\u043f\u0435\u0440\u0435\u0434 \u043e\u0442 this, \u0438 \u0432\u044b \u043d\u0430\u0439\u0434\u0435\u0442\u0435 \u043f\u0430\u043c\u044f\u0442\u044c <code>Grandparent<\/code>. \u041f\u043e\u043d\u044f\u043b\u0438? virtual-base offset \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u0435\u043d top_offset, \u043d\u043e \u0434\u043b\u044f \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u044d\u0442\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0435\u043c, \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 <code>Parent2<\/code> \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0442\u0430\u043a\u043e\u0435 \u0436\u0435, \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <code>construction table for Parent2-in-Child<\/code>. \u0418 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, <code>Parent2-in-Child<\/code> \u0438\u043c\u0435\u0435\u0442 <code>virtual-base offset<\/code> \u0432 16 \u0431\u0430\u0439\u0442\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u0439\u0442\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0432\u043f\u0438\u0442\u0430\u0442\u044c\u0441\u044f. \u0412\u044b \u0433\u043e\u0442\u043e\u0432\u044b \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c? \u0425\u043e\u0440\u043e\u0448\u043e.<br \/>  \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0432\u0435\u0440\u043d\u0435\u043c\u0441\u044f \u043a <code>VTT<\/code>. \u0412\u043e\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <code>VTT<\/code>:<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u0410\u0434\u0440\u0435\u0441<\/th>\n<th>\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435<\/th>\n<th>\u0421\u0438\u043c\u0432\u043e\u043b<\/th>\n<th>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>0x4009a0<\/td>\n<td>0x400950<\/td>\n<td>vtable for Child + 24<\/td>\n<td>\u0417\u0430\u043f\u0438\u0441\u0438 Parent1 \u0432 vtable Child<\/td>\n<\/tr>\n<tr>\n<td>0x4009a8<\/td>\n<td>0x4009f8<\/td>\n<td>construction vtable for Parent1-in-Child + 24<\/td>\n<td>\u041c\u0435\u0442\u043e\u0434\u044b Parent1 \u0432 Parent1-in-Child<\/td>\n<\/tr>\n<tr>\n<td>0x4009b0<\/td>\n<td>0x400a18<\/td>\n<td>construction vtable for Parent1-in-Child + 56<\/td>\n<td>\u041c\u0435\u0442\u043e\u0434\u044b Grandparent \u0434\u043b\u044f Parent1-in-Child<\/td>\n<\/tr>\n<tr>\n<td>0x4009b8<\/td>\n<td>0x400a98<\/td>\n<td>construction vtable for Parent2-in-Child + 24<\/td>\n<td>\u041c\u0435\u0442\u043e\u0434\u044b Parent2 \u0432 Parent2-in-Child<\/td>\n<\/tr>\n<tr>\n<td>0x4009c0<\/td>\n<td>0x400ab8<\/td>\n<td>construction vtable for Parent2-in-Child + 56<\/td>\n<td>`\u041c\u0435\u0442\u043e\u0434\u044b Grandparent \u0434\u043b\u044f Parent2-in-Child<\/td>\n<\/tr>\n<tr>\n<td>0x4009c8<\/td>\n<td>0x400998<\/td>\n<td>vtable for Child + 96<\/td>\n<td>`\u0417\u0430\u043f\u0438\u0441\u0438 Grandparent \u0432 vtable Child<\/td>\n<\/tr>\n<tr>\n<td>0x4009d0<\/td>\n<td>0x400978<\/td>\n<td>vtable for Child + 64<\/td>\n<td>`\u0417\u0430\u043f\u0438\u0441\u0438 Parent2 \u0432 vtable Child<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p><code>VTT<\/code> \u0440\u0430\u0441\u0448\u0438\u0444\u0440\u043e\u0432\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u0430\u043a <code>virtual-table table<\/code> (\u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446), \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u044d\u0442\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430 vtable-\u043e\u0432. \u042d\u0442\u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u043d\u0430\u0435\u0442, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u043b\u0438 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 <code>Parent1<\/code> \u0434\u043b\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430, \u0434\u043b\u044f \u043e\u0431\u044a\u0435\u043a\u0442\u0430 <code>Parent1-in-Child<\/code> \u0438\u043b\u0438 \u0434\u043b\u044f <code>Parent1-in-SomeOtherObject<\/code>. \u041e\u043d\u0430 \u0432\u0441\u0435\u0433\u0434\u0430 \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 <code>vtable<\/code>, \u0447\u0442\u043e\u0431\u044b \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0437\u043d\u0430\u043b, \u0433\u0434\u0435 \u0435\u0435 \u043d\u0430\u0439\u0442\u0438. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0435\u0442 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0434\u0440\u0443\u0433\u043e\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0432 \u0441\u0430\u043c\u0438\u0445 \u043e\u0431\u044a\u0435\u043a\u0442\u0430\u0445.<\/p>\n<p>  <\/p>\n<p>\u0424\u0443\u0445\u2026 \u043c\u043d\u043e\u0433\u043e \u0434\u0435\u0442\u0430\u043b\u0435\u0439, \u043d\u043e \u044f \u0434\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u043c\u044b \u043e\u0445\u0432\u0430\u0442\u0438\u043b\u0438 \u0432\u0441\u0435, \u0447\u0442\u043e \u044f \u0445\u043e\u0442\u0435\u043b \u043e\u0445\u0432\u0430\u0442\u0438\u0442\u044c. \u0412 \u0447\u0435\u0442\u0432\u0435\u0440\u0442\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0434\u0435\u0442\u0430\u043b\u044f\u0445 <code>vtables<\/code> \u0431\u043e\u043b\u0435\u0435 \u0432\u044b\u0441\u043e\u043a\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f. \u041d\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0439\u0442\u0435, \u0442\u0430\u043a \u043a\u0430\u043a \u044d\u0442\u043e, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, \u0441\u0430\u043c\u0430\u044f \u0432\u0430\u0436\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435!<\/p>\n<p>  <\/p>\n<h2 id=\"chast-4---kod-sgenerirovannyy-kompilyatorom\">\u0427\u0430\u0441\u0442\u044c 4 \u2014 \u041a\u043e\u0434, \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c<\/h2>\n<p>  <\/p>\n<p>\u041a \u044d\u0442\u043e\u043c\u0443 \u043c\u043e\u043c\u0435\u043d\u0442\u0443 \u0438\u0437 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u044b \u0443\u0437\u043d\u0430\u043b\u0438, \u043a\u0430\u043a \u0437\u0430\u043f\u0438\u0441\u0438 <code>vtables<\/code> \u0438 <code>typeinfo<\/code> \u043f\u043e\u043c\u0435\u0449\u0430\u044e\u0442\u0441\u044f \u0432 \u043d\u0430\u0448\u0438 \u0434\u0432\u043e\u0438\u0447\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u0438 \u043a\u0430\u043a \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440. \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u044b \u043f\u043e\u0439\u043c\u0435\u043c \u0447\u0430\u0441\u0442\u044c \u0440\u0430\u0431\u043e\u0442\u044b, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u0434\u043b\u044f \u043d\u0430\u0441 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438.<\/p>\n<p>  <\/p>\n<h4 id=\"konstruktory\">\u041a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b<\/h4>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043b\u044e\u0431\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0412\u044b\u0437\u043e\u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0432 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u0435\u0439, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0435\u0441\u0442\u044c;<\/li>\n<li>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 vtable, \u0435\u0441\u043b\u0438 \u043e\u043d\u0438 \u0435\u0441\u0442\u044c;<\/li>\n<li>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0447\u043b\u0435\u043d\u043e\u0432 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0438\u0438 \u0441\u043e \u0441\u043f\u0438\u0441\u043a\u043e\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u043e\u0432;<\/li>\n<li>\u0412\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u0434\u0430 \u0432\u043d\u0443\u0442\u0440\u0438 \u0441\u043a\u043e\u0431\u043e\u043a \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u0432\u044b\u0448\u0435\u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0435 \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c \u0431\u0435\u0437 \u044f\u0432\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430:<\/p>\n<p>  <\/p>\n<ul>\n<li>\u0420\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u044e\u0442\u0441\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u0435\u0441\u043b\u0438 \u043d\u0435 \u0443\u043a\u0430\u0437\u0430\u043d\u043e \u0438\u043d\u043e\u0435;<\/li>\n<li>\u0427\u043b\u0435\u043d\u044b \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e, \u0435\u0441\u043b\u0438 \u0443 \u043d\u0438\u0445 \u043d\u0435\u0442 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0438\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0442\u043e\u0440\u0430;<\/li>\n<li>\u0412\u0435\u0441\u044c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u043e\u043c\u0435\u0447\u0435\u043d = default;<\/li>\n<li>\u0422\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 vtable \u0432\u0441\u0435\u0433\u0434\u0430 \u0441\u043a\u0440\u044b\u0442\u043e.<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">#include &lt;iostream&gt; #include &lt;string&gt; using namespace std;  class Parent { public:     Parent() { Foo(); }     virtual ~Parent() = default;     virtual void Foo() { cout &lt;&lt; \"Parent\" &lt;&lt; endl; }     int i = 0; };  class Child : public Parent { public:     Child() : j(1) { Foo(); }     void Foo() override { cout &lt;&lt; \"Child\" &lt;&lt; endl; }     int j; };  class Grandchild : public Child { public:     Grandchild() { Foo(); s = \"hello\"; }     void Foo() override { cout &lt;&lt; \"Grandchild\" &lt;&lt; endl; }     string s; };  int main() {     Grandchild g; }<\/code><\/pre>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043f\u0441\u0435\u0432\u0434\u043e\u043a\u043e\u0434 \u0434\u043b\u044f \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430:<\/p>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>Parent<\/th>\n<th>Child<\/th>\n<th>Grandchild<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1. vtable = vtable Parent;<\/td>\n<td>1. \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e Parent;<\/td>\n<td>1. \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e Child;<\/td>\n<\/tr>\n<tr>\n<td>2. i = 0;<\/td>\n<td>2. vtable = vtable Child;<\/td>\n<td>2. vtable = vtable Grandchild;<\/td>\n<\/tr>\n<tr>\n<td>3. \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442 Foo();<\/td>\n<td>3. j = 1;<\/td>\n<td>3., \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e s;<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td>4. \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442 Foo();<\/td>\n<td>4. \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442 Foo();<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<td>5. \u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 = \u0434\u043b\u044f s;<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u0423\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u044d\u0442\u043e, \u043d\u0435\u0443\u0434\u0438\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e, \u0447\u0442\u043e \u0432 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043a\u043b\u0430\u0441\u0441\u0430 vtable \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 vtable \u044d\u0442\u043e\u0433\u043e \u0441\u0430\u043c\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430, \u0430 \u043d\u0435 \u043d\u0430 \u0435\u0433\u043e \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441. \u042d\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442, \u0447\u0442\u043e \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u0440\u0430\u0437\u0440\u0435\u0448\u0430\u044e\u0442\u0441\u044f \u0442\u0430\u043a, \u043a\u0430\u043a \u0431\u0443\u0434\u0442\u043e \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u043e\u0432 \u043d\u0435\u0442. \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0432\u044b\u0432\u043e\u0434<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">Parent Child Grandchild<\/code><\/pre>\n<p>  <\/p>\n<p>\u0410 \u043a\u0430\u043a \u043d\u0430\u0441\u0447\u0435\u0442 \u0447\u0438\u0441\u0442\u043e \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439? \u0415\u0441\u043b\u0438 \u043e\u043d\u0438 \u043d\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u044b (\u0434\u0430, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0447\u0438\u0441\u0442\u043e \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u043e \u0437\u0430\u0447\u0435\u043c \u0432\u0430\u043c \u044d\u0442\u043e \u043d\u0430\u0434\u043e?), \u0412\u044b, \u0432\u0435\u0440\u043e\u044f\u0442\u043d\u043e, (\u0438 \u043c\u044b \u043d\u0430\u0434\u0435\u0435\u043c\u0441\u044f) \u043f\u0440\u043e\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0435 \u043f\u0440\u044f\u043c\u0438\u043a\u043e\u043c \u043a segfault. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u044b \u043f\u0440\u0435\u043d\u0435\u0431\u0440\u0435\u0433\u0430\u044e\u0442 \u043e\u0448\u0438\u0431\u043a\u0443, \u0447\u0442\u043e \u043a\u0440\u0443\u0442\u043e.<\/p>\n<p>  <\/p>\n<h4 id=\"destruktory\">\u0414\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b<\/h4>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0435\u0431\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c, \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b \u0432\u0435\u0434\u0443\u0442 \u0441\u0435\u0431\u044f \u0442\u0430\u043a \u0436\u0435, \u043a\u0430\u043a \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b, \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435.<\/p>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u0431\u044b\u0441\u0442\u0440\u043e\u0435 \u0443\u043f\u0440\u0430\u0436\u043d\u0435\u043d\u0438\u0435 \u0434\u043b\u044f \u0440\u0430\u0437\u043c\u044b\u0448\u043b\u0435\u043d\u0438\u044f: \u043f\u043e\u0447\u0435\u043c\u0443 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u044b \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c vtable, \u0447\u0442\u043e\u0431\u044b \u043e\u043d \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u043b \u043d\u0430 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441, \u0430 \u043d\u0435 \u043e\u0441\u0442\u0430\u0432\u043b\u044f\u043b \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441? \u041e\u0442\u0432\u0435\u0442: \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043a \u043c\u043e\u043c\u0435\u043d\u0442\u0443 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0434\u0435\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 \u043b\u044e\u0431\u043e\u0439 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 \u0443\u0436\u0435 \u0431\u044b\u043b \u0443\u043d\u0438\u0447\u0442\u043e\u0436\u0435\u043d. \u0412\u044b\u0437\u043e\u0432 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0442\u0430\u043a\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u2014 \u044d\u0442\u043e \u043d\u0435 \u0442\u043e, \u0447\u0442\u043e \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0434\u0435\u043b\u0430\u0442\u044c.<\/p>\n<p>  <\/p>\n<h4 id=\"neyavnoe-privedenie\">\u041d\u0435\u044f\u0432\u043d\u043e\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h4>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0435\u043b\u0438 \u0432\u043e <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/479802\/\">\u0432\u0442\u043e\u0440\u043e\u0439 \u0438 \u0442\u0440\u0435\u0442\u0435\u0439 \u0447\u0430\u0441\u0442\u0438<\/a>, \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0440\u0430\u0432\u0435\u043d \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u043c\u0443 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044e \u0442\u043e\u0433\u043e \u0436\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u0430 (\u043a\u0430\u043a \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f).<\/p>\n<p>  <\/p>\n<p>\u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0434\u043b\u044f \u0432\u0430\u0441 (\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430) \u043d\u0435\u0442 \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u043e \u0432\u044b\u0437\u043e\u0432\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044f. \u042d\u0442\u043e \u043f\u043e\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u043d\u0435\u044f\u0432\u043d\u043e \u0441\u0434\u0432\u0438\u0433\u0430\u0435\u0442 <code>this<\/code>, \u043a\u043e\u0433\u0434\u0430 \u0432\u044b \u0430\u043f\u043a\u0430\u0441\u0442\u0438\u0442\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u0438 \u0441\u0441\u044b\u043b\u043a\u0438 \u043d\u0430 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0435 \u043a\u043b\u0430\u0441\u0441\u044b.<\/p>\n<p>  <\/p>\n<h4 id=\"dinamicheskoe-privedenie-rtti\">\u0414\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435 (RTTI)<\/h4>\n<p>  <\/p>\n<p>\u041f\u0440\u0438 \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u043e\u043c \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b <code>typeinfo<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0438\u0441\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043b\u0438 \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438. \u041e\u043d\u0438 \u0434\u0435\u043b\u0430\u044e\u0442 \u044d\u0442\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c <code>typeinfo<\/code> \u0437\u0430 \u043e\u0434\u0438\u043d \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u0434\u043e \u0442\u043e\u0433\u043e, \u043d\u0430 \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c <code>vtable<\/code>, \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043a\u043b\u0430\u0441\u0441 \u043e\u0442\u0442\u0443\u0434\u0430, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043b\u0438 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0435.<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u0435\u0442 <a href=\"https:\/\/tinodidriksen.com\/2010\/04\/14\/cpp-dynamic-cast-performance\/\">\u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c dynamic_cast<\/a> \u043f\u0440\u0438 \u0447\u0430\u0441\u0442\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438.<\/p>\n<p>  <\/p>\n<h4 id=\"ukazateli-na-metody\">\u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0438 \u043d\u0430 \u043c\u0435\u0442\u043e\u0434\u044b<\/h4>\n<p>  <\/p>\n<p>\u042f \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u044e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u044b\u0439 \u043f\u043e\u0441\u0442 \u043e\u0431 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f\u0445 \u043d\u0430 \u043c\u0435\u0442\u043e\u0434\u044b \u0432 \u0431\u0443\u0434\u0443\u0449\u0435\u043c. \u0414\u043e \u044d\u0442\u043e\u0433\u043e \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u043f\u043e\u0434\u0447\u0435\u0440\u043a\u043d\u0443\u0442\u044c, \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u043c\u0435\u0442\u043e\u0434, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043d\u0430 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u0443\u044e \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u0431\u0443\u0434\u0435\u0442 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 (\u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u043d\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043d\u0435 \u044f\u0432\u043b\u044f\u044e\u0449\u0438\u0435\u0441\u044f \u0447\u043b\u0435\u043d\u0430\u043c\u0438).<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">\/\/ TODO: \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443, \u043a\u043e\u0433\u0434\u0430 \u043f\u043e\u0441\u0442 \u0431\u0443\u0434\u0435\u0442 \u0433\u043e\u0442\u043e\u0432<\/code><\/pre>\n<p>  <\/p>\n<h4 id=\"proverte-sebya\">\u041f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435 \u0441\u0435\u0431\u044f!<\/h4>\n<p>  <\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u044b \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0438\u0442\u044c \u0441\u0435\u0431\u0435, \u043f\u043e\u0447\u0435\u043c\u0443 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u043a\u043e\u0434\u0430 \u0432\u0435\u0434\u0435\u0442 \u0441\u0435\u0431\u044f \u0442\u0430\u043a, \u043a\u0430\u043a \u043e\u043d \u0441\u0435\u0431\u044f \u0432\u0435\u0434\u0435\u0442:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">#include &lt;iostream&gt; using namespace std;  class FooInterface { public:     virtual ~FooInterface() = default;     virtual void Foo() = 0; };  class BarInterface { public:     virtual ~BarInterface() = default;      virtual void Bar() = 0; };  class Concrete : public FooInterface, public BarInterface { public:     void Foo() override { cout &lt;&lt; \"Foo()\" &lt;&lt; endl; }     void Bar() override { cout &lt;&lt; \"Bar()\" &lt;&lt; endl; } };  int main() {     Concrete c;     c.Foo();     c.Bar();      FooInterface* foo = &amp;c;     foo-&gt;Foo();      BarInterface* bar = (BarInterface*)(foo);     bar-&gt;Bar(); \/\/ \u0412\u044b\u0432\u043e\u0434\u0438\u0442 \"Foo()\" - WTF? }<\/code><\/pre>\n<p>  <\/p>\n<p>\u041d\u0430 \u044d\u0442\u043e\u043c \u044f \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u044e \u0441\u0432\u043e\u044e \u0441\u0442\u0430\u0442\u044c\u044e \u0438\u0437 \u0447\u0435\u0442\u044b\u0440\u0435\u0445 \u0447\u0430\u0441\u0442\u0435\u0439. \u042f \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e \u0432\u044b \u0443\u0437\u043d\u0430\u043b\u0438 \u0447\u0442\u043e-\u0442\u043e \u043d\u043e\u0432\u043e\u0435, \u0442\u0430\u043a \u0436\u0435 \u043a\u0430\u043a \u0438 \u044f.<\/p>\n<\/div>\n<p>               <script class=\"js-mediator-script\">!function(e){function t(t,n){if(!(n in e)){for(var r,a=e.document,i=a.scripts,o=i.length;o--;)if(-1!==i[o].src.indexOf(t)){r=i[o];break}if(!r){r=a.createElement(\"script\"),r.type=\"text\/javascript\",r.async=!0,r.defer=!0,r.src=t,r.charset=\"UTF-8\";var d=function(){var e=a.getElementsByTagName(\"script\")[0];e.parentNode.insertBefore(r,e)};\"[object Opera]\"==e.opera?a.addEventListener?a.addEventListener(\"DOMContentLoaded\",d,!1):e.attachEvent(\"onload\",d):d() } } }t(\"\/\/mediator.mail.ru\/script\/2820404\/\",\"_mediator\")}(window);<\/script>      <br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/480610\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/480610\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html js-mediator-article\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/480610\/\">\n<p><em>\u041f\u0435\u0440\u0435\u0432\u043e\u0434 \u0441\u0442\u0430\u0442\u044c\u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u0434\u043b\u044f \u0441\u0442\u0443\u0434\u0435\u043d\u0442\u043e\u0432 \u043a\u0443\u0440\u0441\u0430 <a href=\"https:\/\/otus.pw\/HhBg\/\">\u00ab\u0420\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0421++\u00bb<\/a>. \u0418\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0440\u0430\u0437\u0432\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0438? \u0421\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0437\u0430\u043f\u0438\u0441\u044c \u043c\u0430\u0441\u0442\u0435\u0440-\u043a\u043b\u0430\u0441\u0441\u0430 <a href=\"https:\/\/otus.pw\/B2p1\/\">\u00ab\u041f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f Google Test Framework\u00bb<\/a>!<\/em><\/p>\n<p>  <\/p>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/tk\/dp\/8n\/tkdp8nfahc7sglqks8sl_tazk1o.png\"><\/p>\n<p>  <\/p>\n<h2 id=\"chast-3---virtualnoe-nasledovanie\">\u0427\u0430\u0441\u0442\u044c 3 \u2014 \u0412\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u0412 <a href=\"https:\/\/habr.com\/ru\/company\/otus\/blog\/479802\/\">\u043f\u0435\u0440\u0432\u043e\u0439 \u0438 \u0432\u0442\u043e\u0440\u043e\u0439 \u0447\u0430\u0441\u0442\u0438<\/a> \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043b\u0438 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a vtables \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0432 \u043f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445, \u0430 \u0437\u0430\u0442\u0435\u043c \u0432 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u043c \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0438. \u0412\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e \u0435\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0435.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-295494","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/295494","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=295494"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/295494\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=295494"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=295494"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=295494"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}