Operator overloading in pure virtual base classes ???
-
Hi,
im have a problem and I dont know how to solve it.
My base class looks like this:class CCounter {
public:
...
virtual void count() = 0;
...
const bool operator< (const CCounter c) const;
const bool operator> (const CCounter c) const;
...
private:
int m_value;
}and from this class I have derived classes, in which I define count(), so that it is not a virutal base class. In these clases, for example CForwardCounter, or CVariableCounter which use different methods of counting. However for all of those i want the same type of comparison, i just want to compare the m_value with normal integer ">" or "<".
This is what my operator< function looks like:
const bool CCounter::operator<(const CCounter c) const
{
if (getValue() < c.getValue()) return true;
return false;
}However now that CCounter is pure virtual I am not allowed to use it any more, hence I cant define the function with a CCounter as an argument.
How do I go around this, without writing a operator< function for each base class.Thanks
-
Declare the arguments as const-references:
const CCounter& c
. You should have done this in any case, abstract class or not.