{"id":4587,"date":"2014-03-30T13:44:24","date_gmt":"2014-03-30T13:44:24","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/templated-class-has-a-circular-dependency-collection-of-common-programming-errors\/"},"modified":"2014-03-30T13:44:24","modified_gmt":"2014-03-30T13:44:24","slug":"templated-class-has-a-circular-dependency-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/templated-class-has-a-circular-dependency-collection-of-common-programming-errors\/","title":{"rendered":"Templated Class has a Circular Dependency-Collection of common programming errors"},"content":{"rendered":"<p>I have two classes. One is a management class, which stores a bunch of worker classes. The workers are actually a templated class.<\/p>\n<pre><code>#include \"worker.h\"    \nclass Management {\n\n     private: \n      worker worker1;\n      worker worker2;\n      ...\n\n};\n<\/code><\/pre>\n<p>The problem arises due to the fact that the templated classes needs to use Management.<\/p>\n<p>Example:<\/p>\n<pre><code>class Worker{\n   ...\n};\n\n#include \"Worker.inl\"\n<\/code><\/pre>\n<p>The Worker inl file:<\/p>\n<pre><code>#include \"Management.h\"  \/\/Circular Dependency!\n\nWorker::Worker(){\n    \/\/Management is accessed here\n    Management mgmt1();\n    mgmt1.doSomething(); \/\/Can't use that forward declaration!\n}\n...\n<\/code><\/pre>\n<p>Normally you would forward declare Management.h in the Worker header file, and call it a day. Sadly, since the class is templated, it is always going to get included.<\/p>\n<p>I guess you can claim that the design is bad, since a templated class shouldn&#8217;t be templated if it needs to know this sort of information, but it is what it is, and I have to work with it.<\/p>\n<p>You can also view this question as a microcosm of office life.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have two classes. One is a management class, which stores a bunch of worker classes. The workers are actually a templated class. #include &#8220;worker.h&#8221; class Management { private: worker worker1; worker worker2; &#8230; }; The problem arises due to the fact that the templated classes needs to use Management. Example: class Worker{ &#8230; }; [&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-4587","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4587","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=4587"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4587\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4587"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4587"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4587"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}