Re: Pure virtual destructor in template class
On 2008-11-18 11:52:08 -0500, Victor Bazarov <v.Abazarov@comAcast.net> said:
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. For example, if a class that implements
java.util.List (which is, roughly, a linked list) also implements
java.util.RandomAccess, it announces that it supports constant-time
random access to elements, so a loop like this:
for (int i = 0, n = list.size(); i <n; i++)
list.get(i);
will supposedly be faster than a loop like this:
for (Iterator i = list.iterator(); i.hasNext(); )
i.next();
You'd use a runtime type check to decide which way to go.
--
Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(www.petebecker.com/tr1book)