M
Marcel Müller
If i have an interface like
template <class K>
struct IComparableTo
{ virtual int compareTo(const K& key) const = 0;
};
some compilers (e.g. gcc) warn me about that the class has virtual
functions but a non-virtual destructor. While this can be helpful in
some cases, it can be annoying too.
If the interface is a template like in the example I get hundreds of
warnings for each type instantiation in each compilation unit.
From the applications point of view it might be not reasonable to
delete the entire object through a particular interface. In such cases I
usually write
template <class K>
struct IComparableTo
{ virtual int compareTo(const K& key) const = 0;
protected:
~ICompareableTo() {}
};
to avoid accidental deletion. But the warnings still hide other, more
important messages.
Is there another way to declare interfaces?
Or are there other good reasons to have virtual destructors on interface
classes?
Marcel
template <class K>
struct IComparableTo
{ virtual int compareTo(const K& key) const = 0;
};
some compilers (e.g. gcc) warn me about that the class has virtual
functions but a non-virtual destructor. While this can be helpful in
some cases, it can be annoying too.
If the interface is a template like in the example I get hundreds of
warnings for each type instantiation in each compilation unit.
From the applications point of view it might be not reasonable to
delete the entire object through a particular interface. In such cases I
usually write
template <class K>
struct IComparableTo
{ virtual int compareTo(const K& key) const = 0;
protected:
~ICompareableTo() {}
};
to avoid accidental deletion. But the warnings still hide other, more
important messages.
Is there another way to declare interfaces?
Or are there other good reasons to have virtual destructors on interface
classes?
Marcel