{"id":3243,"date":"2017-10-27T19:14:58","date_gmt":"2017-10-27T18:14:58","guid":{"rendered":"http:\/\/roboblog.fatal-fury.de\/?p=3243"},"modified":"2017-10-27T19:14:58","modified_gmt":"2017-10-27T18:14:58","slug":"c-guns-multi-derived-crtp","status":"publish","type":"post","link":"http:\/\/roboblog.fatal-fury.de\/?p=3243","title":{"rendered":"C++ Guns - multi derived CRTP"},"content":{"rendered":"<p>As we all know, CRTP is bad. The reasons against you can read on my unpublish Artikel \"Why CRTP is a bad choise\". <\/p>\n<p>Nevermind. Here come a CRTP with a linear derived chain.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\r\n#include &lt;iostream&gt;\r\n\r\nusing namespace std;\r\n\r\ntemplate&lt;typename Child&gt;\r\nstruct 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\ntemplate&lt;typename Child&gt;\r\nstruct Base2 : public Child {\r\n  void func() {\r\n    cout &lt;&lt; &quot;Base2\\n&quot;;\r\n    static_cast&lt;Child*&gt;(this)-&gt;func();\r\n  }\r\n};\r\n\r\nstruct Child {\r\n   void func() {\r\n     cout &lt;&lt; &quot;Child\\n&quot;;\r\n   }\r\n};\r\n\r\n\r\nint main() {\r\n  Base&lt;Base2&lt;Child&gt;&gt; base;\r\n  base.func();\r\n}\r\n<\/pre>\n<pre>\r\nBase\r\nBase2\r\nChild\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>As we all know, CRTP is bad. The reasons against you can read on my unpublish Artikel \"Why CRTP is a bad choise\". Nevermind. Here come a CRTP with a linear derived chain. #include &lt;iostream&gt; using namespace std; template&lt;typename Child&gt; struct Base : public Child { void func() { cout &lt;&lt; &quot;Base\\n&quot;; static_cast&lt;Child*&gt;(this)-&gt;func(); } }; [&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-3243","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\/3243","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=3243"}],"version-history":[{"count":3,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts\/3243\/revisions"}],"predecessor-version":[{"id":3246,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=\/wp\/v2\/posts\/3243\/revisions\/3246"}],"wp:attachment":[{"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3243"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/roboblog.fatal-fury.de\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}