title: Circular Dependency with Inherited Template Class
body: <p>I'm having a circular dependency problem. Basically I have two classes, the first is a template class which uses some functionality from my second class. The second class inherits from my template class. </p>
  
  <p>Below is a simplified structure:</p>
  
  <pre><code>// Foo.h
  #pragma once
  #include "Bar.h"
  
  template &lt;class T&gt; class Foo
  {
       public:
          void DoSomething();
  };
  
  template &lt;class T&gt; void Foo&lt;T&gt;::DoSomething()
  {
       Bar::GetInstance()-&gt;LogEvent();
  }
  
  
  //Bar.h
  #pragma once
  #include "Foo.h"
  
  class Bar : public Foo&lt;Bar&gt;
  {
      public:
          static Bar* GetInstance();
          void LogEvent();
  };
  
  
  //Bar.cpp
  #include "Bar.h"
  
  Bar* Bar::GetInstance()
  {
       // return instance of Bar singleton class
  }
  
  void Bar::LogEvent()
  {
       // log some event in a file
  }
  </code></pre>
  
  <p>Now the problem is when I complile the code I am getting the following errors in bar.h</p>
  
  <pre><code>Bar.h() : error C2504: 'Foo' : base class undefined
  Bar.h() : error C2143: syntax error : missing ',' before '&lt;'
  </code></pre>
  
  <p>From what I can tell this a definitely a dependency problem. If I remove the call to 'LogEvent' from within 'DoSomething', and remove reference "Bar.h" from Foo.h the issue goes away. </p>
  
  <p>However it's not really a solution because Foo needs functionality contained with Bar, conversely bar inherits from Foo and needs to include a reference to Foo.h.</p>
  
  <p>So - how can I resolve this problem? I have looked through the other posts regarding circular references but I haven't been able to solve the problem. </p>
  
  <p>Thanks</p>