grunwald@flute.cs.uiuc.edu (Dirk Grunwald) (03/02/89)
In article <8902280000.AA02932@riunite.aca.mcc.com> rfg@MCC.COM (Ron Guilmette) writes:
(2) The compiler allows you to explicitly declare a destructor as being
virtual but you cannot explicitly declare a constructor as being virtual.
Is this intentional, or is thus a bug?
-- Declaring a destructor to be ``virtual'' means that if I have:
class A { ~A() };
class B : A { ~B() };
A *a; B *b;
b = new B; // all this is ``legal'' so far, if
a = b; // A & B were real classes
delete a;
If ~A() is not virtual, then the delete will call ~A().
If ~A() is virtual, then the delete will call ~B().
This only make sense because we can alias the subclass to the parent class.
You can't do this with constructors. See C++ manual.
(3) If you explicitly declare the destructor for a base
class as being virtual, then there will be a vtable built for that
.....
Feature. See above & C++ manual.
(4) Like the case with destructors, if I have a method
.....
things (a), (b), and (c) are bugs? Which ones are "features"?
All are features. See C++ manual about virtuals. It's not as straight-forward
as it seems. I think that it might be good to have a -W flag to point out
``hidden'' virtuals. This would be particularly useful for people
subclassing library routines. It would let you notice changes to the library
routines that might affect you code.
--
Dirk Grunwald
Univ. of Illinois
grunwald@flute.cs.uiuc.edu