> The current "end goal" is a PriorityQueue template that uses a comparer class
> which is inherited from a "template interface". Basically a pure virtual class
> template. Perhaps that is the mistake to begin with but hopefully not.
> (Is this a valid approach?)
Consider using
std::priority_queue<>
http://en.cppreference.com/w/cpp/container/priority_queue
> The problem I am getting is that when I compile the code, it says my derived comparer class is abstract.
> I need help figuring out why.
In the base class, the parameters are passed by reference.
The derived class does not override the base class functions; instead it adds new virtual functions where the parameters are passed by value.
Make the base class const-correct, and add a virtual destructor:
1 2 3 4 5 6 7 8 9 10
|
template<class T>
class IIMQOBJECTS_EXPORT IQComparer
{
virtual ~IQComparer() = default ;
virtual int compare( const T& a, const T& b) const = 0;
virtual bool equals( const T& a, const T& b) const = 0;
virtual bool isGreaterThan( const T& a, const T& b ) const = 0;
virtual bool isLessThan( const T& a, const T& b) const = 0;
};
|
In the derived class, pass parameters by reference (using a type alias would help simplify matters):
1 2 3 4 5 6 7 8 9 10 11 12 13
|
class APPCORE_EXPORT NetEventInfoComparer : ::IQComparer<NetEventInfo*>
{
public:
NetEventInfoComparer();
~NetEventInfoComparer();
using arg_type = NetEventInfo* ;
virtual int compare( const arg_type& a, const arg_type& b) const override;
virtual bool equals( const arg_type& a, const arg_type& b) const override;
virtual bool isGreaterThan( const arg_type& a, const arg_type& b ) const override;
virtual bool isLessThan( const arg_type& a, const arg_type& b) const override;
};
|
Tip: use the override specifier when the intent is to override a virtual function. The compiler can tell us if we haven't overridden it correctly.
http://en.cppreference.com/w/cpp/language/override