title: Template in a Template of a different types problem
body: <p>I have a template class called Temp, and it have a method takes an argument of the same type:</p>
  
  <pre><code>#ifndef TEMP_H
  #define TEMP_H
  
  template&lt;class T&gt;
  class Temp
  {
      public:
          T data;
          bool comp(T);
  };
  template&lt;class T&gt;
  bool Temp&lt;T&gt;::comp(T data)
  {
      return (this -&gt; data &lt; data);
  }
  #endif // TEMP_H
  </code></pre>
  
  <p>now I want to make an object of class Temp with type of pointer to another class called Foo.</p>
  
  <pre><code>Temp&lt;Foo*&gt; TptrF;
  </code></pre>
  
  <p>usually this is easy and for the method <code>comp</code>, I can do a specialization for this specific type <code>Foo*</code>, but I have to include the file <code>Foo.h</code> in <code>Temp.h</code>:</p>
  
  <pre><code>//Temp.h
  #ifndef TEMP_H
  #define TEMP_H
  #include "Foo.h"
  
  template&lt;class T&gt;
  class Temp
  {
      public:
          T data;
          bool comp(T);
  };
  template&lt;class T&gt;
  bool Temp&lt;T&gt;::comp(T data)
  {
      return (this -&gt; data &lt; data);
  }
  template&lt;&gt;
  inline bool Temp&lt;Foo*&gt;::comp(Foo* data)
  {
      return (this -&gt; data -&gt; val &lt; data -&gt; val);
  }
  #endif // TEMP_H
  </code></pre>
  
  <p>but the problem is that Foo class have an object of type <code>Temp&lt;int&gt;</code> and for this data member in Foo I have to include the file <code>Temp.h</code> in <code>Foo.h</code>:</p>
  
  <pre><code>//Foo.h
  #ifndef FOO_H
  #define FOO_H
  #include "Temp.h"
  
  class Foo
  {
      public:
          int val;
          Temp&lt;int&gt; Ti;
  };
  
  #endif // FOO_H
  </code></pre>
  
  <p>this gives me in <code>Foo.h</code>: </p>
  
  <blockquote>
    <p>error: 'Temp' does not name a type</p>
  </blockquote>
  
  <p>I tried to remove <code>#include "Foo.h"</code> from <code>Temp.h</code> and use a forward declaration instead like <code>class Foo;</code>, but it didn't work as I used the 'val' data member of class Foo in the <code>comp</code> function, and it gives me in <code>Temp.h</code>:</p>
  
  <blockquote>
    <p>error: invalid use of incomplete type 'class Foo'</p>
  </blockquote>
  
  <p>and tried to remove <code>#include "Temp.h"</code> from <code>Foo.h</code>, and use a forward template declaration instead like <code>template&lt;class T&gt; class Temp;</code>,I thought this will work as I just need an object so I just want the compiler to know that I have a template class called Temp, but it also didn't work, and it give me in <code>Foo.h</code>:</p>
  
  <blockquote>
    <p>error: field 'Ti' has incomplete type <code>Temp&lt;int&gt;</code></p>
  </blockquote>
  
  <p>What should I do to make this code work?
  <code>Temp&lt;int&gt;</code> and <code>Temp&lt;Foo*&gt;</code> do not contain each other as objects, so I believe this should work logically, or is it just one of the consequences of bad design.</p>