title: Extending abstract base class with class template
body: <p>How can I extend an abstract base class using templates for the extensions when I also wish to conditionally compile the overrides for the pure virtual functions?</p>
  
  <p>Example: Given the base class</p>
  
  <pre><code>class AbstractBase {
  public:
    virtual void func() = 0;
  };
  </code></pre>
  
  <p>I thought of extending with something like</p>
  
  <pre><code>enum class Opts{FOO, BAR};
  
  template&lt;Opts opt&gt;
  class Derived : public AbstractBase {
  public:
  
    template&lt;Opts op = opt&gt;
    typename std::enable_if&lt;op == Opts::FOO, void&gt;::type func() {
      std::cout &lt;&lt; "Foo" &lt;&lt; "\n";
    }
  
    template&lt;Opts op = opt&gt;
    typename std::enable_if&lt;op == Opts::BAR, void&gt;::type func() {
      std::cout &lt;&lt; "BAR" &lt;&lt; "\n";
    }
  
  };
  </code></pre>
  
  <p>My idea is that when one of the func get to compile in the extended class, then everything's good. However, I can't get it to work.</p>
  
  <pre><code>Derived&lt;Opts::FOO&gt; obj;
  </code></pre>
  
  <p>Will not compile because the derived class is is still abstract. I'm using templates because I want the compiler to pick only one member function to compile.</p>
  
  <p>Thanks.</p>