title: C++ Template no match for operator<
body: <p>I've seen questions similar to this, but haven't found a solution that worked on my problem, so I was hoping I could get some help.</p>
  
  <p>I want to pass a class as an argument to a function with template parameters (For this example I just want it to compile, so nvm that it doesn't make sense with <code>return true</code> in operators). I figured this way in the following code would work:</p>
  
  <pre><code>template&lt;typename T&gt;
  class MyClass {
  public:
      bool operator&gt;(const T&amp;) const { 
          return true;
      }  
  
      bool operator&lt;(const T&amp;) const { 
          return true;
      }
  };
  
  template&lt;typename T, typename S&gt; 
  vector&lt;T&gt; between_interval(T* start, T* end, const S&amp; low, const S&amp; high){
      vector&lt;T&gt; vec;
      for ( ; start != end; start++) {
          if (low &lt; *start &amp;&amp; *start &lt; high)
              vec.push_back(* start);
      }
      return vec;
  }
  
  int main() {
      double v1[] = {1.23, 4.56, 7.89, -10, 4};
      MyClass&lt;double&gt; k1;
      MyClass&lt;double&gt; k2;
      vector&lt;double&gt; res = between_interval(v1, v1 + 3, k1, k2);
      for (auto x : res)
          cout &lt;&lt; x &lt;&lt; " ";
          cout &lt;&lt; endl;
      } 
  </code></pre>
  
  <p>I get the following error(s):</p>
  
  <pre><code>u4.cpp: In instantiation of ‘std::vector&lt;T&gt; between_interval(T*, T*, const S&amp;, const S&amp;) [with T = double; S = MyClass&lt;double&gt;]’:
  u4.cpp:39:55:   required from here
  u4.cpp:28:36: error: no match for ‘operator&lt;’ (operand types are ‘double’ and ‘const MyClass&lt;double&gt;’)
       if (low &lt; *start &amp;&amp; *start &lt; high)
  </code></pre>
  
  <p>I realize passing K1 and K2 won't make sense as it is at the moment, but the compiler doesn't mention this, it complains about not having a match for <code>operator&lt;</code>, so my main question is why? Is it too general with a template argument in <code>operator&lt;</code>? Is there any other way to make the operators work but without using the templates?</p>
  
  <p>Thank you</p>