"delete this;" in const member function?

Ingolf Koch ingolf@mathematik.uni-jena.de
Mon Feb 9 07:35:00 GMT 1998


Hi,

the following might not be standard compliant:

class A {
    public:
        A* clone() const {return new A(*this);}
        void kill() const {delete this;}
};

Is it allowed to "delete this" in a const member function?
egcs compiles this piece of code without any warning (even
when -Wall is given), while for example DEC cxx 5.7 treats
it as an error.

Regards
-- 

Ingolf Koch         http://www.minet.uni-jena.de/~ingolf/ 
FSU Jena, Institut fuer Angewandte Mathematik, 07740 Jena



More information about the Gcc-bugs mailing list