Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Virtual method but non-virtual destructor

Tags:

c++

I get the error "Class 'Polygon' has virtual method 'area' but non-virtual destructor" in Eclipse CDT. Why? Code snippet:

Header files:

class Shape {
public:
    virtual ~Shape();
protected:
    virtual double area() const = 0;
}

class Polygon : public Shape {
    public:  
        ~Polygon();
    protected:
        double area() const;
    private:
        Vertex* vertices; 
}

Implementation:

Polygon::~Polygon() {delete[] this->vertices;}
double Polygon::area() const {
    ...
    return areaSum;
}
like image 677
Emil Avatar asked Aug 25 '11 19:08

Emil


1 Answers

Sounds like a bug in eclipse, or maybe it's a 'style' warning about a minor issue. Polygon does have a virtual destructor automatically because it's base class destructor is virtual.

like image 136
john Avatar answered Sep 28 '22 23:09

john