title: C++ template duck-typing vs pure virtual base class inheritance
body: <p>Which are the guidelines for choosing between template duck-typing and pure virtual base class inheritance? Examples:</p>
  
  <pre><code>// templates
  class duck {
      void sing() { std::cout &lt;&lt; "quack\n"; }
  };
  
  template&lt;typename bird&gt;
  void somefunc(const bird&amp; b) {
      b.sing();
  }
  
  // pure virtual base class
  class bird {
      virtual void sing() = 0;
  };
  
  class duck : public bird {
      void sing() { std::cout &lt;&lt; "quack\n"; }
  }
  
  void somefunc(const bird&amp; b) {
      b.sing();
  }
  </code></pre>