Re: Pure virtual destructor in template class
On 2008-11-18 17:48:34 -0500, James Kanze <james.kanze@gmail.com> said:
On Nov 18, 6:06??pm, Pete Becker <p...@versatilecoding.com> wrote:
On 2008-11-18 11:52:08 -0500, Victor Bazarov <v.Abaza...@comAcast.net> sa
id:
Tonni Tielens wrote:
I'm trying to create a pure virtual class describing an
interface. Normally, when I do this I make the destructor
pure virtual so that, even if there are no members in the
class, it cannot be instantiated.
Why would you have an interface with no other members?
??Wouldn't it be pretty much useless as an interface?
It's a Java thing.
I don't think it's only Java. It's known as a tagging
interface, and it potentially has a role in any staticly typed
language which supports polymorphism. I think I've actually
used it once in C++; C++ usually has other ways of solving the
problem, however, which are generally preferred (because they
can be made to work with non class types as well). Even in the
standard, the iterator_tag hierarchy could be considered an
example of this.
Well, maybe, but for that you don't need a virtual destructor. In the
part of my message that you snipped I pointed out how this is used in
Java. The analogous usage in C++ does require a virtual destructor in
order to be able to test for that (mixin) base with dynamic_cast.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)