title: std::sort using inherited functor
body: <p>I would like to use different strategies to sort a vector. But I can't figure out how to pass a child functor and use it in <code>std::sort</code> later on. Whenever I use abstract class for sorting strategy I end up with <code>cannot allocate an object of abstract type</code> error. Is there a way to use inherited functors as <code>std::sort</code> arguments? Thanks!</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  using namespace std;
  
  
  class BaseSort{
  public:
      virtual ~BaseSort() {};
      virtual bool operator()(const int&amp; a, const int&amp; b) = 0;
  };
  
  class Asc : public BaseSort{
  public:
      bool operator()(const int&amp; a, const int&amp; b){
          return a &lt; b;
      }
  };
  
  class Desc : public BaseSort{
  public:
      bool operator()(const int&amp; a, const int&amp; b){
          return a &gt; b;
      }
  };
  
  void print(const vector&lt;int&gt;&amp; values) {
      for (unsigned i = 0; i &lt; values.size(); ++i) {
          cout &lt;&lt; values[i] &lt;&lt; ' ';
      }
      cout &lt;&lt; endl;
  }
  
  int main() {
      vector&lt;int&gt; values = {2,1,3};
      sort(values.begin(), values.end(), Asc()); // {1,2,3}
      print(values);
      sort(values.begin(), values.end(), Desc()); // {3,2,1}
      print(values);
      Asc* asc = new Asc();
      sort(values.begin(), values.end(), *asc); // {1,2,3}
      print(values);
      BaseSort* sortStrategy = new Desc();
      sort(values.begin(), values.end(), *sortStrategy); //cannot allocate an object of abstract type ‘BaseSort’
      print(values);
      return 0;
  }
  </code></pre>