title: Adding overload operator == with enable_if
body: <p>I have a working template class point with an overload for <code>operator==</code>.</p>
  
  <p>Because of floating point comparison, I was trying to add a second overload with <code>enable_if</code> for floating point to use an almost equal function.</p>
  
  <p>This is my attempt:</p>
  
  <pre><code>template&lt;typename T&gt;
  class Point2D
  {
  public:
     Point2D(T x, T y);
  
     Point2D&amp; operator= (const Point2D&amp; point);
     bool     operator==(const Point2D&amp; point) const;
     bool     operator!=(const Point2D&amp; point) const;
  };
  
  template&lt;typename T&gt;
  Point2D&lt;T&gt;::Point2D(T x, T y) : x_(x), y_(y)
  {
  }
  
  template&lt;typename T&gt;
  Point2D&lt;T&gt;&amp; Point2D&lt;T&gt;::operator=(const Point2D&amp; point)
  {
     if(this != &amp;point)
     {
        x_ = point.x_;
        y_ = point.y_;
     }
  
     return *this;
  }
  
  template&lt;typename T&gt;
  bool Point2D&lt;T&gt;::operator==(const Point2D&amp; point) const
  {
     return (x_ == point.x_) &amp;&amp; (y_ == point.y_);
  }
  
  template&lt;typename T&gt;
  typename std::enable_if&lt;std::is_floating_point&lt;T&gt;::value, bool&gt;::type
  Point2D&lt;T&gt;::operator==(const Point2D&amp; point) const
  {
     return Traits::almost_equal(x_, point.x_) &amp;&amp;
            Traits::almost_equal(y_, point.y_);
  }
  </code></pre>
  
  <p><strong>Note:</strong></p>
  
  <ul>
  <li><p>This is a semplified example.</p></li>
  <li><p>The code actually work without the enable_if overload</p></li>
  <li><p>I have to separate declaration and implementation (both in .h), so please refer to the code as is.</p></li>
  </ul>
  
  <p>The error the compiler gives me is</p>
  
  <blockquote>
  <pre><code>error: prototype for typename std::enable_if&lt;std::is_floating_point&lt;_Tp&gt;::value, bool&gt;::type Point2D&lt;T&gt;::operator==(const Point2D&lt;T&gt;&amp;) const
    does not match any in class Point2D&lt;T&gt;
    Point2D&lt;T&gt;::operator==(const Point2D&amp; point) const
    ^
  
  error: candidate is: bool Point2D&lt;T&gt;::operator==(const Point2D&lt;T&gt;&amp;)
  const bool Point2D&lt;T&gt;::operator==(const Point2D&amp; point) const
        ^
  </code></pre>
  </blockquote>
  
  <p>I don't understand what the error is referring to.</p>