I am implementing a quick sort algorithm. I have a interface
class Comparable{
public:
virtual int compareTo(Comparable *c)=0;
};
and now I have a class called ComparableInt, which implements Comparable:
class ComparableInt: public algorithm::Comparable{
public:
int value;
int compareTo(Comparable *i) {
ComparableInt *c = dynamic_cast<ComparableInt*>(i);
return value - (*c).value;
};
ComparableInt(int i):value(i){};
};
My question is, is this the correct way to do it? I was try to implement it like this:
class ComparableInt: public algorithm::Comparable{
public:
int value;
int compareTo(ComparableInt *i) {
return value - (*i).value;
};
ComparableInt(int i):value(i){};
};
but it seems that this int compareTo(ComparableInt *i) is not a implemention for virtual int compareTo(Comparable *c), so I have to do a dynamic cast. Seeking for your kind help!