<p>When comparing two objects (of the same type), it makes sense to have a compare function which takes another instance of the same class. If I implement this as a virtual function in the base class, then the signature of the function has to reference the base class in derived classes also. What is the elegant way to tackle this? Should the Compare not be virtual?</p>

<pre><code>class A
{
    A();
    ~A();
    virtual int Compare(A Other);
}

class B: A
{
    B();
    ~B();
    int Compare(A Other);
}

class C: A
{
    C();
    ~C();
    int Compare(A Other);
}
</code></pre>

If you mean that the Compare() in class B or C should always be passed an object of class B or C, no matter what the signature says, you can work with pointers to instances instead of instances, and try to downcast the pointer in the method's code using something like
```
```
int B::Compare(A *ptr)
{
   other = dynamic_cast <B*> (ptr);
   if(other)
      ...  // Ok, it was a pointer to B
}
```
```
(Such an overloading would be necessary only for those derived classes that add to the state of their parent something that influences the comparison.)