why can't i pass two different comparators to one template function?
<p>I'm wracking my brain here for several hours, but I still don't understand why I'm getting an error when I'm trying to run this code.
After some time I managed to narrow it down to the expression: </p>

<pre><code>pastryPrice()
</code></pre>

<p>which causes the problem - as you can see, I'm trying to build numerous comparators for one template function of sorting</p>

<pre><code>    struct dialingAreaComp{
    inline bool operator()(const Deliver *d1, const Deliver *d2)const {
        return d1-&gt;getDialingArea() &lt; d2-&gt;getDialingArea();
    }
};
struct pastryPrice {
    inline bool operator()(const Pastry *p1, const Pastry *p2)const {
        return p1-&gt;getPrice() &lt; p2-&gt;getPrice();
    }
};
template&lt;class T&gt;
void sortCollection(T&amp; collection)
{
    if ( typeid (collection) == typeid(vector &lt;Deliver*&gt;))
    {
        sort(collection.begin(), collection.end(), dialingAreaComp());
        printCollection(collection);
    }
    else if (typeid (collection) == typeid(vector &lt;Pastry*&gt;))
    {
        sort(collection.begin(), collection.end(), pastryPrice());
        printCollection(collection);
    }
    else { cout &lt;&lt; "WRONG!"; }
}
</code></pre>

<p>I'm getting five errors, all the same:</p>

<blockquote>
  <p>Severity  Code    Description Project File    Line    Suppression State
  Error   C2664   'bool Bakery::pastryPrice::operator ()(const Pastry *,const Pastry *) const': cannot convert argument 1 from 'Deliver *' to 'const Pastry *'    Bakery  c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility 809 </p>
</blockquote>

<p>And one more:</p>

<blockquote>
  <p>Severity  Code    Description Project File    Line    Suppression State
  Error   C2056   illegal expression  Bakery  c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility 809 </p>
</blockquote>

<p>When I take off the expression I wrote above, the code works <strong>just fine</strong> - why can't I pass two different comparators to one template function?</p>

<p>Now:</p>

<blockquote>
  <p>C2264 is a Compiler Error that occurs when one tries to pass a function a parameter of an incompatible type.</p>
</blockquote>

<p>But the Deliver function works and when I took off the Deliver comparator the Pastry compiled as well... so what is the incompatible type? </p>