title: Partial specialization of a method in a templated class
body: <p>Given:</p>
  
  <pre><code>struct A
  {
      virtual bool what() = 0;
  };
  
  template&lt;typename T, typename Q&gt;
  struct B : public A
  {
      virtual bool what();
  };
  </code></pre>
  
  <p>I want to partially specialize <code>what</code> like:</p>
  
  <pre><code>template&lt;typename T, typename Q&gt;
  bool B&lt;T, Q&gt;::what()
  {
      return true;
  }
  
  template&lt;typename Q&gt;
  bool B&lt;float, Q&gt;::what()
  {
      return false;
  }
  </code></pre>
  
  <p>But it appears that this isn't possible (is it in C++11?) so I tried SFINAE:</p>
  
  <pre><code>template&lt;typename T&gt;
  typename std::enable_if&lt;std::is_same&lt;T, float&gt;::value, bool&gt;::type B&lt;T&gt;::what()
  {
      return true;
  }
  
  template&lt;typename T&gt;
  typename std::enable_if&lt;!std::is_same&lt;T, float&gt;::value, bool&gt;::type B&lt;T&gt;::what()
  {
      return false;
  }
  </code></pre>
  
  <p>This also doesn't work, I have no idea why though, does anyone? So I found <a href="https://stackoverflow.com/questions/1501357/template-specialization-of-particular-members/1501455#1501455">this thread</a> and ended up with:</p>
  
  <pre><code>template&lt;typename T, typename Q&gt;
  struct B : public A
  {
      virtual bool what()
      {
          return whatimpl(std::is_same&lt;T, float&gt;());
      }
  
      bool whatimpl(std::false_type)
      {
          return false;
      }
  
      bool whatimpl(std::true_type)
      {
          return true;
      }
  };
  </code></pre>
  
  <p>This final solution works, but why doesn't the <code>enable_if</code> technique work? I'm also very open to suggestions of a cleaner answer that I haven't encountered yet.</p>
  
  <p>I simplified my examples as much as possible - in my real use case <code>what()</code> isn't called <em>what</em> and actually does a fair bit of work, and I'll want to 'specialize' on a user defined type, not <code>float</code>.</p>