{"id":3247,"date":"2017-10-27T19:27:59","date_gmt":"2017-10-27T18:27:59","guid":{"rendered":"http:\/\/roboblog.fatal-fury.de\/?p=3247"},"modified":"2017-10-27T19:28:10","modified_gmt":"2017-10-27T18:28:10","slug":"c-guns-multi-derived-crtp-more-pain","status":"publish","type":"post","link":"http:\/\/roboblog.fatal-fury.de\/?p=3247","title":{"rendered":"C++ Guns - multi derived CRTP - more pain"},"content":{"rendered":"<p>And because we love pain, here come the CRTP diamond derive.<br \/>\nHave fun with these. (no, don't)<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n  #include &lt;iostream&gt;\r\n\r\n  using namespace std;\r\n\r\n  template&lt;typename Child, typename Child2&gt;\r\n  struct UltraBase : public Child, public Child2 {\r\n    void func() {\r\n      cout &lt;&lt; &quot;UltraBase\\n&quot;;\r\n      static_cast&lt;Child*&gt;(this)-&gt;func();\r\n    }\r\n    \r\n    void func2() {\r\n      cout &lt;&lt; &quot;UltraBase\\n&quot;;\r\n      static_cast&lt;Child2*&gt;(this)-&gt;func2();\r\n    }\r\n  };\r\n  \r\n  template&lt;typename Child&gt;\r\n  struct Base : public Child {\r\n    void func() {\r\n      cout &lt;&lt; &quot;Base\\n&quot;;\r\n      static_cast&lt;Child*&gt;(this)-&gt;func();\r\n    }\r\n  };\r\n\r\n  template&lt;typename Child&gt;\r\n  struct Base2 : public Child {\r\n    void func2() {\r\n      cout &lt;&lt; &quot;Base2\\n&quot;;\r\n      static_cast&lt;Child*&gt;(this)-&gt;func2();\r\n    }\r\n  };\r\n\r\n  struct Child {\r\n    void func() {\r\n      cout &lt;&lt; &quot;Child\\n&quot;;\r\n    }\r\n    \r\n    void func2() {\r\n      cout &lt;&lt; &quot;Child2\\n&quot;;\r\n    }\r\n  };\r\n\r\n\r\n  int main() {\r\n    UltraBase&lt;Base&lt;Child&gt;, Base2&lt;Child&gt;&gt; ultrabase;\r\n    ultrabase.func();\r\n    ultrabase.func2();\r\n  }\r\n<\/pre>\n<pre>\r\nUltraBase\r\nBase\r\nChild\r\nUltraBase\r\nBase2\r\nChild2\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>And because we love pain, here come the CRTP diamond derive. Have fun with these. (no, don't) #include &lt;iostream&gt; using namespace std; template&lt;typename Child, typename Child2&gt; struct UltraBase : public Child, public Child2 { void func() { cout &lt;&lt; &quot;UltraBase\\n&quot;; static_cast&lt;Child*&gt;(this)-&gt;func(); } void func2() { cout &lt;&lt; &quot;UltraBase\\n&quot;; static_cast&lt;Child2*&gt;(this)-&gt;func2(); } }; template&lt;typename Child&gt; struct Base [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[17],"class_list":["post-3247","post","type-post","status-publish","format-standard","hentry","category-allgemein","tag-cpp"],"_links":{"self":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts\/3247","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3247"}],"version-history":[{"count":4,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts\/3247\/revisions"}],"predecessor-version":[{"id":3251,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts\/3247\/revisions\/3251"}],"wp:attachment":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3247"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3247"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3247"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}