{"id":4207,"date":"2014-03-30T09:16:07","date_gmt":"2014-03-30T09:16:07","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/implementing-interfaces-in-c-collection-of-common-programming-errors\/"},"modified":"2014-03-30T09:16:07","modified_gmt":"2014-03-30T09:16:07","slug":"implementing-interfaces-in-c-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/implementing-interfaces-in-c-collection-of-common-programming-errors\/","title":{"rendered":"Implementing interfaces in C++-Collection of common programming errors"},"content":{"rendered":"<p>As others have noted, the two functions in the base classes are unrelated (despite having the same name and argument types), as they have no common base class. If you want them to be related, you need to give them a common base class.<\/p>\n<p>Also, in general, if you want multiple inheritance to work properly, you need to declare your non-private base classes as <code>virtual<\/code>. Otherwise, if you ever have common base classes (as you often need for this style of code), bad things will happen.<\/p>\n<p>So given that, you can make your example work as follows:<\/p>\n<pre><code>template \nclass IDoSomething {\npublic:\n    virtual void DoSomething(T value) = 0;\n};\n\ntemplate \nclass Base : public virtual IDoSomething\n{\npublic:\n    virtual void DoSomething(T value)\n    {\n        \/\/ Do something here\n    }\n};\n\nclass IDoubleDoSomething : public virtual IDoSomething\n{\n};\n\nclass Foo : public virtual Base, public virtual IDoubleDoSomething\n{\n};\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>As others have noted, the two functions in the base classes are unrelated (despite having the same name and argument types), as they have no common base class. If you want them to be related, you need to give them a common base class. Also, in general, if you want multiple inheritance to work properly, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4207","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4207","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4207"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4207\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}