[comp.lang.c++] Bugs in pure virtual functions?

jenings@hpfcbig.SDE.HP.COM (Byron T. Jenings Jr.) (12/02/89)

I am building a class hierarchy where each class item needs to have a
virtual destructor.  This is because I want to be able to free a tree
of these object by calling delete on a pointer to the abstract class.
Here's a fragment of the code:

class Expression
{
public:
    virtual ~Expression() = 0;
    virtual void print() = 0;
    virtual int value() = 0;
};

class Or : public Expression
{
    Expression *left, *right;
public:
    Or(Expression *, Expression *);
    ~Or();
    void print();
    int value();
};

etc...

The problem is, C++ 2.0 requires me to actually define an
implementation for the destructor ~Expression, even though it is a
pure virtual function.  This is because it is implicitly called by the
constructors of the derived classes.

This seems like a bug to me, since the whole idea of pure virtual
funtions [I thought] was that they had no definition.

-----

Another problem with this same example.  C++ 2.0 generates the
following warning:

"Expression.h", line 14: warning: Expression  has Expression::~Expression() but no constructor

This doesn't seem appropriate since the destructor is a pure virtual
constructor, and there's no such thing as a pure virtual constructor.
The compiler is basically forcing me to define a dummy constructor in
my abstract class, which isn't supposed to have any executable code
associated with it in the first place.


    Byron Jenings (HP4000/UX) <jenings@hpfclp>
    Phone (303)229-6080
    Software Engineering Systems Division, Mailstop #7
    Hewlett-Packard Co., Ft. Collins CO 80525-9599