Re: Interfaces and non-virtual destructors
Pete Becker wrote:
On 2008-08-23 08:02:54 -0400, Marcel M??ller
<news.5.maazl@spamgourmet.org> said:
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.
That's what happens when compiler writers assume that they know more
about your application than you do. Surely, though, there's a
command-line switch to turn off this warning.
Well, compiler warnings are meant to catch programmer's oversights.
There's always a trade-off between their helpfulness, risk of false
positives and corresponding compiler complexity. With gcc 4.2.2 (see
my other post) that's IMHO quite a good trade-off.
For the records, you can disable the warning with -Wno-non-virtual-dtor.
--
Gennaro Prota | name.surname yahoo.com
Breeze C++ (preview): <https://sourceforge.net/projects/breeze/>
Do you need expertise in C++? I'm available.