This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

operator delete() redefinition errors.



Running the 980517 snapshot of egcs (egcs-2.91.29) under
Solaris 2.51 with no special compile options, I'm seeing some
weird behavior when redefining operator delete() in my classes.

Here's a minimal program showing the problems.

--------------------------------------

class Base
{
public:
 
    virtual ~Base() { }
 
    void operator delete(void* pMemory)
        { ::operator delete(pMemory); }
};
 
 
class Derived : public Base
{
public:
 
    void operator delete(void* pMemory)
        { Base::operator delete(pMemory); }
};

 
class VirtualDerived : virtual public Base
{
public:
 
    void operator delete(void* pMemory)
        { Base::operator delete(pMemory); }
};
 
 
int
main()
{
    Base* pBase = new Base;
 
    Derived* pDerived = new Derived;
 
    VirtualDerived* pVirtualDerived = new VirtualDerived;
 
    return 0;
}

--------------------------------------

Compiling this gives errors on the lines which allocate the
Derived object and VirtualDerived object.  The errors are:

no suitable operator delete for `Derived'
no suitable operator delete for `VirtualDerived'

Removing the virtual destructor in Base gets rid of the first
error, but the second remains.  So, the error appears to be
related to both virtual destructors and virtual inheritance
when redefining operator delete().

Taking the destructor definition in Base out of line does not
change anything.  Nor does implementing the operator delete
redefinitions in terms of the global delete (::operator delete).

For your info,

Jeff Wegher
JWegher@NEONSoft.com



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]