{"id":295764,"date":"2019-12-17T16:26:33","date_gmt":"2019-12-17T16:26:33","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=295764"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=295764","title":{"rendered":"C++ vtables. \u0427\u0430\u0441\u0442\u044c 1 (basics + multiple Inheritance)"},"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\/479802\/\">\n<p><em>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \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\/d2qJ\/\">\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? \u041f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0435 \u043e\u043d\u043b\u0430\u0439\u043d 13 \u0434\u0435\u043a\u0430\u0431\u0440\u044f \u0432 20:00 \u043f\u043e \u043c\u0441\u043a. \u043d\u0430 \u043c\u0430\u0441\u0442\u0435\u0440-\u043a\u043b\u0430\u0441\u0441 <a href=\"https:\/\/otus.pw\/x79M\/\">\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\/eh\/lh\/ox\/ehlhoxzs1sz7v7xtni9lizjefxq.png\"><\/p>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a clang \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 vtables (\u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432) \u0438 RTTI (\u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e \u0442\u0438\u043f\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f). \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0430 \u0437\u0430\u0442\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0438 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435.<a name=\"habracut\"><\/a><\/p>\n<p>  <\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043d\u0430\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u043e\u0438\u0442 \u043f\u043e\u043a\u043e\u043f\u0430\u0442\u044c\u0441\u044f \u0432 \u0434\u0432\u043e\u0438\u0447\u043d\u043e\u043c \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0438, \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u0434\u043b\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u0435\u0439 \u043d\u0430\u0448\u0435\u0433\u043e \u043a\u043e\u0434\u0430, \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e gdb. \u042d\u0442\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043d\u0438\u0437\u043a\u0438\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c, \u043d\u043e \u044f \u0441\u0434\u0435\u043b\u0430\u044e \u0432\u0441\u044e \u0442\u044f\u0436\u0435\u043b\u0443\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0437\u0430 \u0432\u0430\u0441. \u042f \u043d\u0435 \u0434\u0443\u043c\u0430\u044e, \u0447\u0442\u043e \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0431\u0443\u0434\u0443\u0449\u0438\u0445 \u043f\u043e\u0441\u0442\u043e\u0432 \u0431\u0443\u0434\u0443\u0442 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0434\u0435\u0442\u0430\u043b\u0438 \u0442\u0430\u043a\u043e\u0433\u043e \u043d\u0438\u0437\u043a\u043e\u0433\u043e \u0443\u0440\u043e\u0432\u043d\u044f.<\/p>\n<p>  <\/p>\n<blockquote><p><em>\u0414\u0438\u0441\u043a\u043b\u0435\u0439\u043c\u0435\u0440<\/em>: \u0432\u0441\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u0435 \u0437\u0434\u0435\u0441\u044c \u0437\u0430\u0432\u0438\u0441\u0438\u0442 \u043e\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043c\u043e\u0436\u0435\u0442 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c\u0441\u044f \u0432 \u043b\u044e\u0431\u043e\u0439 \u0431\u0443\u0434\u0443\u0449\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438, \u0442\u0430\u043a \u0447\u0442\u043e \u043d\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043d\u0430 \u044d\u0442\u043e \u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c\u0441\u044f. \u041c\u044b \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c \u044d\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0446\u0435\u043b\u044f\u0445. <\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/webt\/40\/po\/du\/40podustjhxkcl7_keexd9uea2e.png\"><\/p>\n<p>  <\/p>\n<p>\u043e\u0442\u043b\u0438\u0447\u043d\u043e, \u0442\u043e\u0433\u0434\u0430 \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043d\u0430\u0447\u043d\u0435\u043c.<\/p>\n<p>  <\/p>\n<h2 id=\"chast-1---vtables---osnovy\">\u0427\u0430\u0441\u0442\u044c 1 \u2014 vtables \u2014 \u041e\u0441\u043d\u043e\u0432\u044b<\/h2>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">#include &lt;iostream&gt; using namespace std;  class NonVirtualClass {  public:   void foo() {} };  class VirtualClass {  public:   virtual void foo() {} };  int main() {   cout &lt;&lt; \"Size of NonVirtualClass: \" &lt;&lt; sizeof(NonVirtualClass) &lt;&lt; endl;   cout &lt;&lt; \"Size of VirtualClass: \" &lt;&lt; sizeof(VirtualClass) &lt;&lt; endl; }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ # \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0439\u0442\u0435 \u0438 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u0435 main.cpp $ clang++ main.cpp &amp;&amp; .\/a.out Size of NonVirtualClass: 1 Size of VirtualClass: 8<\/code><\/pre>\n<p>  <\/p>\n<p><code>NonVirtualClass<\/code> \u0438\u043c\u0435\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440 1 \u0431\u0430\u0439\u0442, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432 C++ \u043a\u043b\u0430\u0441\u0441\u044b \u043d\u0435 \u043c\u043e\u0433\u0443\u0442 \u0438\u043c\u0435\u0442\u044c \u043d\u0443\u043b\u0435\u0432\u043e\u0439 \u0440\u0430\u0437\u043c\u0435\u0440. \u041e\u0434\u043d\u0430\u043a\u043e \u0441\u0435\u0439\u0447\u0430\u0441 \u044d\u0442\u043e \u043d\u0435 \u0432\u0430\u0436\u043d\u043e.<\/p>\n<p>  <\/p>\n<p>\u0420\u0430\u0437\u043c\u0435\u0440 <code>VirtualClass<\/code> \u0441\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 8 \u0431\u0430\u0439\u0442 \u043d\u0430 64-\u0431\u0438\u0442\u043d\u043e\u0439 \u043c\u0430\u0448\u0438\u043d\u0435. \u041f\u043e\u0447\u0435\u043c\u0443? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u043d\u0443\u0442\u0440\u0438 \u0435\u0441\u0442\u044c \u0441\u043a\u0440\u044b\u0442\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043d\u0430 vtable. vtables \u2014 \u044d\u0442\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0442\u0440\u0430\u043d\u0441\u043b\u044f\u0446\u0438\u0438, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0435\u043c\u044b\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430. \u042d\u0442\u0430 \u0441\u0442\u0430\u0442\u044c\u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043e\u0431 \u0438\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0438 \u0438 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u043e\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f.<\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u0433\u043b\u0443\u0431\u043e\u043a\u043e\u0435 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0442\u043e\u0433\u043e, \u043a\u0430\u043a \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 vtables, \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043e\u0434 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e gdb, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u044f\u0441\u043d\u0438\u0442\u044c, \u043a\u0430\u043a \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 \u043f\u0430\u043c\u044f\u0442\u044c:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">#include &lt;iostream&gt;  class Parent {  public:   virtual void Foo() {}   virtual void FooNotOverridden() {} };  class Derived : public Parent {  public:   void Foo() override {} };  int main() {   Parent p1, p2;   Derived d1, d2;    std::cout &lt;&lt; \"done\" &lt;&lt; std::endl; }<\/code><\/pre>\n<p>  <\/p>\n<pre><code class=\"plaintext\">$ # \u0441\u043a\u043e\u043c\u043f\u0438\u043b\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448 \u043a\u043e\u0434 \u0441 \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u044b\u043c\u0438 \u0441\u0438\u043c\u0432\u043e\u043b\u0430\u043c\u0438 \u0438 \u043d\u0430\u0447\u043d\u0435\u043c \u043e\u0442\u043b\u0430\u0434\u043a\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f gdb $ clang++ -std=c++14 -stdlib=libc++ -g main.cpp &amp;&amp; gdb .\/a.out ... (gdb) # \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c gdb \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u0434\u0435-\u0434\u0435\u043a\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0438\u043c\u0432\u043e\u043b\u044b C++ (gdb) set print asm-demangle on (gdb) set print demangle on (gdb) # \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u0442\u043e\u0447\u043a\u0443 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0430 \u043d\u0430 main (gdb) b main Breakpoint 1 at 0x4009ac: file main.cpp, line 15. (gdb) run Starting program: \/home\/shmike\/cpp\/a.out  Breakpoint 1, main () at main.cpp:15 15    Parent p1, p2; (gdb) # \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 (gdb) n 16    Derived d1, d2; (gdb) # \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0442\u0440\u043e\u043a\u0435 (gdb) n 18    std::cout &lt;&lt; \"done\" &lt;&lt; std::endl; (gdb) # \u0432\u044b\u0432\u0435\u0434\u0435\u043c p1, p2, d1, d2 - \u043c\u044b \u0441\u043a\u043e\u0440\u043e \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u0432\u044b\u0432\u043e\u0434 (gdb) p p1 $1 = {_vptr$Parent = 0x400bb8 &lt;vtable for Parent+16&gt;} (gdb) p p2 $2 = {_vptr$Parent = 0x400bb8 &lt;vtable for Parent+16&gt;} (gdb) p d1 $3 = {&lt;Parent&gt; = {_vptr$Parent = 0x400b50 &lt;vtable for Derived+16&gt;}, &lt;No data fields&gt;} (gdb) p d2 $4 = {&lt;Parent&gt; = {_vptr$Parent = 0x400b50 &lt;vtable for Derived+16&gt;}, &lt;No data fields&gt;}<\/code><\/pre>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u0447\u0442\u043e \u043c\u044b \u0443\u0437\u043d\u0430\u043b\u0438 \u0438\u0437 \u0432\u044b\u0448\u0435\u0438\u0437\u043b\u043e\u0436\u0435\u043d\u043d\u043e\u0433\u043e:<br \/>  \u2014 \u041d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0442\u043e, \u0447\u0442\u043e \u0443 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043d\u0435\u0442 \u0447\u043b\u0435\u043d\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445, \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u0441\u043a\u0440\u044b\u0442\u044b\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 vtable;<br \/>  \u2014 vtable \u0434\u043b\u044f p1 \u0438 p2 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432. vtables \u2014 \u044d\u0442\u043e \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0438\u043f\u0430;<br \/>  \u2014 d1 \u0438 d2 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u044e\u0442 vtable-\u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043e\u0442 Parent, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 vtable Derived;<br \/>  \u2014 \u0412\u0441\u0435 vtables \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442 \u043d\u0430 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 16 (0x10) \u0431\u0430\u0439\u0442\u043e\u0432 \u0432 vtable. \u042d\u0442\u043e \u043c\u044b \u0442\u0430\u043a\u0436\u0435 \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u043f\u043e\u0437\u0436\u0435.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u043c \u043d\u0430\u0448\u0443 gdb-\u0441\u0435\u0441\u0441\u0438\u044e, \u0447\u0442\u043e\u0431\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 vtables. \u042f \u0431\u0443\u0434\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043c\u0430\u043d\u0434\u0443 x, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u043f\u0430\u043c\u044f\u0442\u044c \u043d\u0430 \u044d\u043a\u0440\u0430\u043d. \u041c\u044b \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u043c\u0441\u044f \u0432\u044b\u0432\u0435\u0441\u0442\u0438 300 \u0431\u0430\u0439\u0442\u043e\u0432 \u0432 \u0448\u0435\u0441\u0442\u043d\u0430\u0434\u0446\u0430\u0442\u0435\u0440\u0438\u0447\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435, \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 0x400b40. \u041f\u043e\u0447\u0435\u043c\u0443 \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e\u0442 \u0430\u0434\u0440\u0435\u0441? \u041f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0432\u044b\u0448\u0435 \u043c\u044b \u0432\u0438\u0434\u0435\u043b\u0438, \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c vtable \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 0x400b50, \u0430 \u0441\u0438\u043c\u0432\u043e\u043b \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0430\u0434\u0440\u0435\u0441\u0430 <code>vtable for Derived+16 (16 == 0x10)<\/code>.<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">(gdb) x\/300xb 0x400b40 0x400b40 &lt;vtable for Derived&gt;:  0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00 0x400b48 &lt;vtable for Derived+8&gt;:    0x90    0x0b    0x40    0x00    0x00    0x00    0x00    0x00 0x400b50 &lt;vtable for Derived+16&gt;:   0x80    0x0a    0x40    0x00    0x00    0x00    0x00    0x00 0x400b58 &lt;vtable for Derived+24&gt;:   0x90    0x0a    0x40    0x00    0x00    0x00    0x00    0x00 0x400b60 &lt;typeinfo name for Derived&gt;:   0x37    0x44    0x65    0x72    0x69    0x76    0x65    0x64 0x400b68 &lt;typeinfo name for Derived+8&gt;: 0x00    0x36    0x50    0x61    0x72    0x65    0x6e    0x74 0x400b70 &lt;typeinfo name for Parent+7&gt;:  0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00 0x400b78 &lt;typeinfo for Parent&gt;: 0x90    0x20    0x60    0x00    0x00    0x00    0x00    0x00 0x400b80 &lt;typeinfo for Parent+8&gt;:   0x69    0x0b    0x40    0x00    0x00    0x00    0x00    0x00 0x400b88:   0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00 0x400b90 &lt;typeinfo for Derived&gt;:    0x10    0x22    0x60    0x00    0x00    0x00    0x00    0x00 0x400b98 &lt;typeinfo for Derived+8&gt;:  0x60    0x0b    0x40    0x00    0x00    0x00    0x00    0x00 0x400ba0 &lt;typeinfo for Derived+16&gt;: 0x78    0x0b    0x40    0x00    0x00    0x00    0x00    0x00 0x400ba8 &lt;vtable for Parent&gt;:   0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00 0x400bb0 &lt;vtable for Parent+8&gt;: 0x78    0x0b    0x40    0x00    0x00    0x00    0x00    0x00 0x400bb8 &lt;vtable for Parent+16&gt;:    0xa0    0x0a    0x40    0x00    0x00    0x00    0x00    0x00 0x400bc0 &lt;vtable for Parent+24&gt;:    0x90    0x0a    0x40    0x00    0x00    0x00    0x00    0x00 ...<\/code><\/pre>\n<p>  <\/p>\n<blockquote><p>\u041f\u0440\u0438\u043c\u0435\u0447\u0430\u043d\u0438\u0435: \u043c\u044b \u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0434\u0435-\u0434\u0435\u043a\u043e\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 (demangled) \u0441\u0438\u043c\u0432\u043e\u043b\u044b. \u0415\u0441\u043b\u0438 \u0432\u0430\u043c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, _ZTV \u2014 \u044d\u0442\u043e \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0434\u043b\u044f vtable, _ZTS \u2014 \u044d\u0442\u043e \u043f\u0440\u0435\u0444\u0438\u043a\u0441 \u0434\u043b\u044f \u0441\u0442\u0440\u043e\u043a\u0438 \u0442\u0438\u043f\u0430 (\u0438\u043c\u0435\u043d\u0438), \u0430 _ZTI \u0434\u043b\u044f typeinfo.<\/p><\/blockquote>\n<p>  <\/p>\n<hr>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <code>vtable Parent<\/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>0x400ba8<\/td>\n<td>0x0<\/td>\n<td>top_offset (\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u043f\u043e\u0437\u0436\u0435)<\/td>\n<\/tr>\n<tr>\n<td>0x400bb0<\/td>\n<td>0x400b78<\/td>\n<td>\u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 typeinfo for Parent (\u0442\u0430\u043a\u0436\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0432\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0433\u043e \u0434\u0430\u043c\u043f\u0430 \u043f\u0430\u043c\u044f\u0442\u0438)<\/td>\n<\/tr>\n<tr>\n<td>0x400bb8<\/td>\n<td>0x400aa0<\/td>\n<td>\u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 Parent::Foo() <em>(1)<\/em>. _vptr Parent \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u044e\u0434\u0430.<\/td>\n<\/tr>\n<tr>\n<td>0x400bc0<\/td>\n<td>0x400a90<\/td>\n<td>\u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 Parent::FooNotOverridden() <em>(2)<\/em><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 <code>vtable Derived<\/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>0x400b40<\/td>\n<td>0x0<\/td>\n<td>top_offset (\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u043f\u043e\u0437\u0436\u0435)<\/td>\n<\/tr>\n<tr>\n<td>0x400b48<\/td>\n<td>0x400b90<\/td>\n<td>\u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 typeinfo for Derived (\u0442\u0430\u043a\u0436\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0447\u0430\u0441\u0442\u044c\u044e \u0432\u044b\u0448\u0435\u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u043d\u043e\u0433\u043e \u0434\u0430\u043c\u043f\u0430 \u043f\u0430\u043c\u044f\u0442\u0438)<\/td>\n<\/tr>\n<tr>\n<td>0x400b50<\/td>\n<td>0x400a80<\/td>\n<td>\u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 Derived::Foo() <em>(3)<\/em>.,_vptr Derived \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u044e\u0434\u0430.<\/td>\n<\/tr>\n<tr>\n<td>0x400b58<\/td>\n<td>0x400a90<\/td>\n<td>\u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 Parent::FooNotOverridden() (\u0442\u0430\u043a\u043e\u0439 \u0436\u0435, \u043a\u0430\u043a \u0438 \u0443 Parent)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>1:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">(gdb) # \u0432\u044b\u044f\u0441\u043d\u0438\u043c, \u043a\u0430\u043a\u043e\u0439 \u043e\u0442\u043b\u0430\u0434\u043e\u0447\u043d\u044b\u0439 \u0441\u0438\u043c\u0432\u043e\u043b \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0434\u043b\u044f \u0430\u0434\u0440\u0435\u0441\u0430 0x400aa0 (gdb) info symbol 0x400aa0 Parent::Foo() in section .text of a.out<\/code><\/pre>\n<p>  <\/p>\n<p>2:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">(gdb) info symbol 0x400a90 Parent::FooNotOverridden() in section .text of a.out<\/code><\/pre>\n<p>  <\/p>\n<p>3:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">(gdb) info symbol 0x400a80 Derived::Foo() in section .text of a.out<\/code><\/pre>\n<p>  <\/p>\n<p>\u041f\u043e\u043c\u043d\u0438\u0442\u0435, \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c vtable \u0432 Derived \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u043b \u043d\u0430 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 +16 \u0431\u0430\u0439\u0442\u043e\u0432 \u0432 vtable? \u0422\u0440\u0435\u0442\u0438\u0439 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0430\u0434\u0440\u0435\u0441\u043e\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430. \u0425\u043e\u0442\u0438\u0442\u0435 \u0442\u0440\u0435\u0442\u0438\u0439 \u043c\u0435\u0442\u043e\u0434? \u041d\u0435\u0442 \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u2014 \u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 2 <em> sizeof(void<\/em>) \u043a \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044e vtable. \u0425\u043e\u0442\u0438\u0442\u0435 \u0437\u0430\u043f\u0438\u0441\u044c typeinfo? \u043f\u0435\u0440\u0435\u0439\u0434\u0438\u0442\u0435 \u043a \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044e \u043f\u0435\u0440\u0435\u0434 \u043d\u0438\u043c.<\/p>\n<p>  <\/p>\n<p>\u0414\u0432\u0438\u0433\u0430\u0435\u043c\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435 \u2014 \u043a\u0430\u043a \u043d\u0430\u0441\u0447\u0435\u0442 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0437\u0430\u043f\u0438\u0441\u0435\u0439 typeinfo?<\/p>\n<p>  <\/p>\n<p><code>Parent<\/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>0x400b78<\/td>\n<td>0x602090<\/td>\n<td>\u0412\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432 type_info <em>(1)<\/em><\/td>\n<\/tr>\n<tr>\n<td>0x400b80<\/td>\n<td>0x400b69<\/td>\n<td>\u0421\u0442\u0440\u043e\u043a\u0430, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0430\u044f \u0438\u043c\u044f \u0442\u0438\u043f\u0430 <em>(2)<\/em><\/td>\n<\/tr>\n<tr>\n<td>0x400b88<\/td>\n<td>0x0<\/td>\n<td>0 \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 typeinfo<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u0410 \u0432\u043e\u0442 \u0437\u0430\u043f\u0438\u0441\u044c <code>typeinfo Derived<\/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>0x400b90<\/td>\n<td>0x602210<\/td>\n<td>\u0412\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0434\u043b\u044f \u043c\u0435\u0442\u043e\u0434\u043e\u0432 type_info <em>(3)<\/em><\/td>\n<\/tr>\n<tr>\n<td>0x400b98<\/td>\n<td>0x400b60<\/td>\n<td>\u0421\u0442\u0440\u043e\u043a\u0430, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0449\u0430\u044f \u0438\u043c\u044f \u0442\u0438\u043f\u0430 <em>(4)<\/em><\/td>\n<\/tr>\n<tr>\n<td>0x400ba0<\/td>\n<td>0x400b78<\/td>\n<td>\u0423\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c typeinfo Parent<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>1:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">(gdb) info symbol 0x602090 vtable for __cxxabiv1::__class_type_info@@CXXABI_1.3 + 16 in section .bss of a.out<\/code><\/pre>\n<p>  <\/p>\n<p>2:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">(gdb) x\/s 0x400b69 0x400b69 &lt;typeinfo name for Parent&gt;:    \"6Parent\"<\/code><\/pre>\n<p>  <\/p>\n<p>3:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">(gdb) info symbol 0x602210 vtable for __cxxabiv1::__si_class_type_info@@CXXABI_1.3 + 16 in section .bss of a.out<\/code><\/pre>\n<p>  <\/p>\n<p>4:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">(gdb) x\/s 0x400b60 0x400b60 &lt;typeinfo name for Derived&gt;:   \"7Derived\"<\/code><\/pre>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u0443\u0437\u043d\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u043e __si_class_type_info, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e <a href=\"https:\/\/refspecs.linuxfoundation.org\/LSB_4.0.0\/LSB-CXX-generic\/LSB-CXX-generic\/baselib.html\">\u0437\u0434\u0435\u0441\u044c<\/a>, \u0430 \u0442\u0430\u043a\u0436\u0435 <a href=\"https:\/\/gcc.gnu.org\/onlinedocs\/gcc-4.6.2\/libstdc++\/api\/a01094_source.html\">\u0437\u0434\u0435\u0441\u044c<\/a>.<\/p>\n<p>  <\/p>\n<p>\u042d\u0442\u043e \u0438\u0441\u0447\u0435\u0440\u043f\u044b\u0432\u0430\u0435\u0442 \u043c\u043e\u0438 \u043d\u0430\u0432\u044b\u043a\u0438 \u0441 gdb, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442 \u044d\u0442\u0443 \u0447\u0430\u0441\u0442\u044c. \u042f \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u044e, \u0447\u0442\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043b\u044e\u0434\u0438 \u0441\u043e\u0447\u0442\u0443\u0442 \u044d\u0442\u043e \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u043d\u0438\u0437\u043a\u0438\u043c \u0443\u0440\u043e\u0432\u043d\u0435\u043c, \u0438\u043b\u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043f\u0440\u043e\u0441\u0442\u043e \u043d\u0435 \u0438\u043c\u0435\u044e\u0449\u0438\u043c \u043f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0446\u0435\u043d\u043d\u043e\u0441\u0442\u0438. \u0415\u0441\u043b\u0438 \u044d\u0442\u043e \u0442\u0430\u043a, \u044f \u0431\u044b \u043f\u043e\u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u043e\u0432\u0430\u043b \u043f\u0440\u043e\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u0447\u0430\u0441\u0442\u0438 2 \u0438 3, \u043f\u0435\u0440\u0435\u0439\u0434\u044f \u043f\u0440\u044f\u043c\u043e \u043a <a href=\"https:\/\/shaharmike.com\/cpp\/vtable-part4\/\">\u0447\u0430\u0441\u0442\u0438 4<\/a>.<\/p>\n<p>  <\/p>\n<h2 id=\"chast-2---mnozhestvennoe-nasledovanie\">\u0427\u0430\u0441\u0442\u044c 2 \u2014 \u041c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435<\/h2>\n<p>  <\/p>\n<p>\u041c\u0438\u0440 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0439 \u043e\u0434\u0438\u043d\u043e\u0447\u043d\u043e\u0433\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0449\u0435 \u0434\u043b\u044f \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u0430. \u041a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0435\u043b\u0438 \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438, \u043a\u0430\u0436\u0434\u044b\u0439 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 vtable, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043d\u043e\u0432\u043e\u0433\u043e \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430.<\/p>\n<p>  <\/p>\n<p>\u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e, \u0434\u0430\u0436\u0435 \u043a\u043e\u0433\u0434\u0430 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0438\u0441\u0442\u043e \u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \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\">class Mother {  public:   virtual void MotherMethod() {}   int mother_data; };  class Father {  public:   virtual void FatherMethod() {}   int father_data; };  class Child : public Mother, public Father {  public:   virtual void ChildMethod() {}   int child_data; };<\/code><\/pre>\n<p>  <\/p>\n<div class=\"scrollable-table\">\n<table>\n<thead>\n<tr>\n<th>\u0421\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0430 Child<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>_vptr$Mother<\/td>\n<\/tr>\n<tr>\n<td>mother_data (+ \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435)<\/td>\n<\/tr>\n<tr>\n<td>_vptr$Father<\/td>\n<\/tr>\n<tr>\n<td>father_data<\/td>\n<\/tr>\n<tr>\n<td>child_data <em>(1)<\/em><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u0435\u0441\u0442\u044c 2 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f vtable. \u0418\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e \u044f \u0431\u044b \u043e\u0436\u0438\u0434\u0430\u043b 1 \u0438\u043b\u0438 3 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f (Mother, Father \u0438 Child). \u041d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u043d\u0435\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u043e\u0434\u0438\u043d \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c (\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u0434\u0430\u043b\u0435\u0435), \u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0443\u043c\u0435\u043d, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0439 vtable Child \u043a\u0430\u043a \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435 vtable Mother, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u044f \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c 1 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c.<\/p>\n<p>  <\/p>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u0443 Child \u043d\u0435 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043e\u0434\u043d\u043e\u0433\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f vtable \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0442\u0440\u0435\u0445 \u0442\u0438\u043f\u043e\u0432? \u041f\u043e\u043c\u043d\u0438\u0442\u0435, \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c Child \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u043d \u0432 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0449\u0443\u044e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c Mother \u0438\u043b\u0438 Father, \u0438 \u043e\u0431\u0430 \u0431\u0443\u0434\u0443\u0442 \u043e\u0436\u0438\u0434\u0430\u0442\u044c, \u0447\u0442\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c this \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0445 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f\u0445. \u042d\u0442\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u044b \u0437\u043d\u0430\u0442\u044c \u043e Child, \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e \u043d\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u0442\u044c, \u0447\u0442\u043e Child \u2014 \u044d\u0442\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0442\u043e, \u0447\u0442\u043e \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043f\u043e\u0434 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u043c Mother\/Father, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043e\u043d\u0438 \u043e\u043f\u0435\u0440\u0438\u0440\u0443\u044e\u0442.<\/p>\n<p>  <\/p>\n<p><em>(1) \u041d\u0435 \u0438\u043c\u0435\u0435\u0442 \u043e\u0442\u043d\u043e\u0448\u0435\u043d\u0438\u044f \u043a \u044d\u0442\u043e\u0439 \u0442\u0435\u043c\u0435, \u043d\u043e, \u0442\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0447\u0442\u043e child_data \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0438 Father. \u042d\u0442\u043e \u043d\u0430\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u00abtail padding\u00bb \u0438 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0442\u0435\u043c\u043e\u0439 \u0431\u0443\u0434\u0443\u0449\u0435\u0433\u043e \u043f\u043e\u0441\u0442\u0430.<\/em><\/p>\n<p>  <\/p>\n<p>\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>0x4008b8<\/td>\n<td>0<\/td>\n<td>top_offset (\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u043f\u043e\u0437\u0436\u0435)<\/td>\n<\/tr>\n<tr>\n<td>0x4008c0<\/td>\n<td>0x400930<\/td>\n<td>\u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 typeinfo for Child<\/td>\n<\/tr>\n<tr>\n<td>0x4008c8<\/td>\n<td>0x400800<\/td>\n<td>Mother::MotherMethod(). _vptr$Mother \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u0441\u044e\u0434\u0430.<\/td>\n<\/tr>\n<tr>\n<td>0x4008d0<\/td>\n<td>0x400810<\/td>\n<td>Child::ChildMethod()<\/td>\n<\/tr>\n<tr>\n<td>0x4008d8<\/td>\n<td>-16<\/td>\n<td>top_offset (\u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u043f\u043e\u0437\u0436\u0435)<\/td>\n<\/tr>\n<tr>\n<td>0x4008e0<\/td>\n<td>0x400930<\/td>\n<td>\u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 typeinfo for Child<\/td>\n<\/tr>\n<tr>\n<td>0x4008e8<\/td>\n<td>0x400820<\/td>\n<td>Father::FatherMethod(). _vptr$Father \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 \u044d\u0442\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 Child \u0431\u0443\u0434\u0435\u0442 \u0438\u043c\u0435\u0442\u044c \u0442\u043e\u0442 \u0436\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u0438 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0438 \u043a \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044e Mother. \u041d\u043e \u043f\u0440\u0438 \u043f\u0440\u0438\u0432\u0435\u0434\u0435\u043d\u0438\u0438 \u043a \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044e Father \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0432\u044b\u0447\u0438\u0441\u043b\u044f\u0435\u0442 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f this, \u0447\u0442\u043e\u0431\u044b \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0430 _vptr$Father \u0447\u0430\u0441\u0442\u044c Child (3-\u0435 \u043f\u043e\u043b\u0435 \u0432 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0435 Child, \u0441\u043c. \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0432\u044b\u0448\u0435).<\/p>\n<p>  <\/p>\n<p>\u0414\u0440\u0443\u0433\u0438\u043c\u0438 \u0441\u043b\u043e\u0432\u0430\u043c\u0438, \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e Child c;: (void<em>)&amp;c != (void<\/em>)static_cast&lt;Father*&gt;(&amp;c). \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043b\u044e\u0434\u0438 \u043d\u0435 \u043e\u0436\u0438\u0434\u0430\u044e\u0442 \u044d\u0442\u043e\u0433\u043e, \u0438, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043e\u0434\u043d\u0430\u0436\u0434\u044b \u044d\u0442\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442 \u0432\u0430\u043c \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u043e\u0442\u043b\u0430\u0434\u043a\u0443. <\/p>\n<p>  <\/p>\n<p>\u042f \u043d\u0430\u0445\u043e\u0434\u0438\u043b \u044d\u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u044b\u043c \u043d\u0435 \u043e\u0434\u0438\u043d \u0440\u0430\u0437. \u041d\u043e \u043f\u043e\u0434\u043e\u0436\u0434\u0438\u0442\u0435, \u044d\u0442\u043e \u0435\u0449\u0435 \u043d\u0435 \u0432\u0441\u0435.<\/p>\n<p>  <\/p>\n<p>\u0427\u0442\u043e, \u0435\u0441\u043b\u0438 Child \u0440\u0435\u0448\u0438\u043b \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043e\u0434\u0438\u043d \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 Father? \u0420\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">class Mother {  public:   virtual void MotherFoo() {} };  class Father {  public:   virtual void FatherFoo() {} };  class Child : public Mother, public Father {  public:   void FatherFoo() override {} };<\/code><\/pre>\n<p>  <\/p>\n<p>\u0421\u0438\u0442\u0443\u0430\u0446\u0438\u044f \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0441\u043b\u043e\u0436\u043d\u0435\u0435. \u0424\u0443\u043d\u043a\u0446\u0438\u044f \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0442\u044c \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442 Father* \u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c FatherFoo() \u0434\u043b\u044f \u043d\u0435\u0433\u043e. \u041d\u043e \u0435\u0441\u043b\u0438 \u0432\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0434\u0438\u0442\u0435 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 Child, \u043e\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e \u043e\u043d \u0432\u044b\u0437\u043e\u0432\u0435\u0442 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 Child \u0441 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u043c this. \u0422\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435, \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u043e\u043d \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 Child. \u041e\u043d \u0438\u043c\u0435\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c \u043d\u0430 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 Child, \u0433\u0434\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0435\u043d\u0438\u0435 Father. \u041a\u0442\u043e-\u0442\u043e \u0434\u043e\u043b\u0436\u0435\u043d \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044f this, \u043d\u043e \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c? \u041a\u0430\u043a\u0443\u044e \u043c\u0430\u0433\u0438\u044e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u044d\u0442\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c?<\/p>\n<p>  <\/p>\n<p><em>\u041f\u0440\u0435\u0436\u0434\u0435 \u0447\u0435\u043c \u043c\u044b \u043e\u0442\u0432\u0435\u0442\u0438\u043c \u043d\u0430 \u044d\u0442\u043e, \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 Mother \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043c\u0443\u0434\u0440\u0435\u043d\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c this \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432. Child \u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0447\u0438\u0442\u0430\u0442\u044c \u043f\u043e\u0441\u043b\u0435 vtable Mother, \u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u0442, \u0447\u0442\u043e \u043c\u0435\u0442\u043e\u0434\u044b Child \u0431\u0443\u0434\u0443\u0442 \u0441\u0440\u0430\u0437\u0443 \u043f\u043e\u0441\u043b\u0435 \u043d\u0435\u0435.<\/em><\/p>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 \u0440\u0435\u0448\u0435\u043d\u0438\u0435: \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \u201d\u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043d\u0438\u043a\u201d (thunk), \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u044c this, \u0430 \u0437\u0430\u0442\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u201c\u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0439\u201d \u043c\u0435\u0442\u043e\u0434. \u0410\u0434\u0440\u0435\u0441 \u043c\u0435\u0442\u043e\u0434\u0430-\u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043d\u0438\u043a\u0430 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043f\u043e\u0434 vtable Father, \u0432 \u0442\u043e \u0432\u0440\u0435\u043c\u044f \u043a\u0430\u043a \u201c\u043d\u0430\u0441\u0442\u043e\u044f\u0449\u0438\u0439\u201d \u043c\u0435\u0442\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434 vtable Child.<\/p>\n<p>  <\/p>\n<p>\u0412\u043e\u0442 <code>vtable Child<\/code>:<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">0x4008e8 &lt;vtable for Child&gt;:    0x00    0x00    0x00    0x00    0x00    0x00    0x00    0x00 0x4008f0 &lt;vtable for Child+8&gt;:  0x60    0x09    0x40    0x00    0x00    0x00    0x00    0x00 0x4008f8 &lt;vtable for Child+16&gt;: 0x00    0x08    0x40    0x00    0x00    0x00    0x00    0x00 0x400900 &lt;vtable for Child+24&gt;: 0x10    0x08    0x40    0x00    0x00    0x00    0x00    0x00 0x400908 &lt;vtable for Child+32&gt;: 0xf8    0xff    0xff    0xff    0xff    0xff    0xff    0xff 0x400910 &lt;vtable for Child+40&gt;: 0x60    0x09    0x40    0x00    0x00    0x00    0x00    0x00 0x400918 &lt;vtable for Child+48&gt;: 0x20    0x08    0x40    0x00    0x00    0x00    0x00    0x00<\/code><\/pre>\n<p>  <\/p>\n<p>\u0427\u0442\u043e \u043e\u0437\u043d\u0430\u0447\u0430\u0435\u0442:<\/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>0x4008e8<\/td>\n<td>0<\/td>\n<td>top_offset (\u0441\u043a\u043e\u0440\u043e!)<\/td>\n<\/tr>\n<tr>\n<td>0x4008f0<\/td>\n<td>0x400960<\/td>\n<td>typeinfo for Child<\/td>\n<\/tr>\n<tr>\n<td>0x4008f8<\/td>\n<td>0x400800<\/td>\n<td>Mother::MotherFoo()<\/td>\n<\/tr>\n<tr>\n<td>0x400900<\/td>\n<td>0x400810<\/td>\n<td>Child::FatherFoo()<\/td>\n<\/tr>\n<tr>\n<td>0x400908<\/td>\n<td>-8<\/td>\n<td>top_offset<\/td>\n<\/tr>\n<tr>\n<td>0x400910<\/td>\n<td>0x400960<\/td>\n<td>typeinfo for Child<\/td>\n<\/tr>\n<tr>\n<td>0x400918<\/td>\n<td>0x400820<\/td>\n<td>\u043d\u0435 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043d\u0438\u043a Child::FatherFoo()<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>  <\/p>\n<p>\u041e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435: \u043a\u0430\u043a \u043c\u044b \u0432\u0438\u0434\u0435\u043b\u0438 \u0440\u0430\u043d\u0435\u0435, \u0443 Child \u0435\u0441\u0442\u044c 2 vtables \u2014 \u043e\u0434\u043d\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f Mother \u0438 Child, \u0430 \u0434\u0440\u0443\u0433\u0430\u044f \u0434\u043b\u044f Father. \u0412 vtable Father, FatherFoo() \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430 \u201c\u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043d\u0438\u043a\u201d, \u0430 \u0432 vtable Child \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043d\u0430 Child::FatherFoo().<\/p>\n<p>  <\/p>\n<p>\u0410 \u0447\u0442\u043e \u0432 \u044d\u0442\u043e\u043c \u201c\u043f\u0435\u0440\u0435\u0445\u043e\u0434\u043d\u0438\u043a\u0435\u201d, \u0441\u043f\u0440\u043e\u0441\u0438\u0442\u0435 \u0432\u044b?<\/p>\n<p>  <\/p>\n<pre><code class=\"plaintext\">(gdb) disas \/m 0x400820, 0x400850 Dump of assembler code from 0x400820 to 0x400850: 15    void FatherFoo() override {}    0x0000000000400820 &lt;non-virtual thunk to Child::FatherFoo()+0&gt;:  push   %rbp    0x0000000000400821 &lt;non-virtual thunk to Child::FatherFoo()+1&gt;:  mov    %rsp,%rbp    0x0000000000400824 &lt;non-virtual thunk to Child::FatherFoo()+4&gt;:  sub    $0x10,%rsp    0x0000000000400828 &lt;non-virtual thunk to Child::FatherFoo()+8&gt;:  mov    %rdi,-0x8(%rbp)    0x000000000040082c &lt;non-virtual thunk to Child::FatherFoo()+12&gt;: mov    -0x8(%rbp),%rdi    0x0000000000400830 &lt;non-virtual thunk to Child::FatherFoo()+16&gt;: add    $0xfffffffffffffff8,%rdi    0x0000000000400837 &lt;non-virtual thunk to Child::FatherFoo()+23&gt;: callq  0x400810 &lt;Child::FatherFoo()&gt;    0x000000000040083c &lt;non-virtual thunk to Child::FatherFoo()+28&gt;: add    $0x10,%rsp    0x0000000000400840 &lt;non-virtual thunk to Child::FatherFoo()+32&gt;: pop    %rbp    0x0000000000400841 &lt;non-virtual thunk to Child::FatherFoo()+33&gt;: retq       0x0000000000400842:  nopw   %cs:0x0(%rax,%rax,1)    0x000000000040084c:  nopl   0x0(%rax)<\/code><\/pre>\n<p>  <\/p>\n<p>\u041a\u0430\u043a \u043c\u044b \u0443\u0436\u0435 \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0438 \u2014 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f this \u0438 \u0432\u044b\u0437\u043e\u0432 FatherFoo(). \u0418 \u043d\u0430 \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0441\u043c\u0435\u0441\u0442\u0438\u0442\u044c this, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c Child? top_offset!<\/p>\n<p>  <\/p>\n<p><em>\u041e\u0431\u0440\u0430\u0442\u0438\u0442\u0435 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435, \u0447\u0442\u043e \u044f \u043b\u0438\u0447\u043d\u043e \u0441\u0447\u0438\u0442\u0430\u044e, \u0447\u0442\u043e \u0438\u043c\u044f non-virtual thunk \u0447\u0440\u0435\u0437\u0432\u044b\u0447\u0430\u0439\u043d\u043e \u0437\u0430\u043f\u0443\u0442\u0430\u043d\u043d\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u044d\u0442\u043e \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0434\u043b\u044f \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u042f \u043d\u0435 \u0443\u0432\u0435\u0440\u0435\u043d, \u0447\u0442\u043e \u0442\u0443\u0442 \u043d\u0435 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e, \u043d\u043e \u044d\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043c\u043e\u0435 \u043c\u043d\u0435\u043d\u0438\u0435.<\/em><\/p>\n<p>  <\/p>\n<hr>\n<p>  <\/p>\n<p><em>\u041f\u043e\u043a\u0430 \u043d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0451, \u0432 \u0431\u043b\u0438\u0436\u0430\u0439\u0448\u0435\u043c \u0431\u0443\u0434\u0443\u0449\u0435\u043c \u043f\u0435\u0440\u0435\u0432\u0435\u0434\u0435\u043c 3 \u0438 4 \u0447\u0430\u0441\u0442\u0438. \u0421\u043b\u0435\u0434\u0438\u0442\u0435 \u0437\u0430 \u043d\u043e\u0432\u043e\u0441\u0442\u044f\u043c\u0438!<\/em><\/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\/479802\/\"> https:\/\/habr.com\/ru\/company\/otus\/blog\/479802\/<\/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\/479802\/\">\n<p><em>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \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\/d2qJ\/\">\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? \u041f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0435 \u043e\u043d\u043b\u0430\u0439\u043d 13 \u0434\u0435\u043a\u0430\u0431\u0440\u044f \u0432 20:00 \u043f\u043e \u043c\u0441\u043a. \u043d\u0430 \u043c\u0430\u0441\u0442\u0435\u0440-\u043a\u043b\u0430\u0441\u0441 <a href=\"https:\/\/otus.pw\/x79M\/\">\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\/eh\/lh\/ox\/ehlhoxzs1sz7v7xtni9lizjefxq.png\"><\/p>\n<p>  <\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c, \u043a\u0430\u043a clang \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 vtables (\u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432) \u0438 RTTI (\u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044e \u0442\u0438\u043f\u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438\u0441\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f). \u0412 \u043f\u0435\u0440\u0432\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u043c\u044b \u043d\u0430\u0447\u043d\u0435\u043c \u0441 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432, \u0430 \u0437\u0430\u0442\u0435\u043c \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u0438 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\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-295764","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/295764","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=295764"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/295764\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=295764"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=295764"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=295764"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}