overloading delete operator

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RS24
    New Member
    • Oct 2006
    • 9

    overloading delete operator

    Hi!

    Is it true that we can overload delete operator in a class only once?

    If yes, why is it so?
  • D_C
    Contributor
    • Jun 2006
    • 293

    #2
    How many ways is there to delete a class? There is a default destructor, which can be implemented. I assume delete calls the destructor.

    If you have two destructors, how does delete know which destructor to call? It doesn't. Besides, you can put a conditional statement inside the destructor and only execute part of it, effectively combining two destructors into one.

    I suppose there may be pointers to objects that are still active and should not be deleted, which may lead to conditional deletion of class members.

    Regardless, one destructor is sufficient. I don't think that qualifies as overloading. You should have two or more implementations for overloading.

    Comment

    Working...