destructors

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Aniruddh
    New Member
    • Aug 2007
    • 1

    destructors

    Why does delete *this calls destructor twice.
    How do we solve this problem
  • questionit
    Contributor
    • Feb 2007
    • 553

    #2
    Hi Aniruddh

    Destructor should only be called once.

    Do you have loops in your program? In your program, do you have piece of code which runs within a loop; and that code actually assigns NULL to the object or anything like that?

    How are you determining that destructor is being called twice?

    Qi


    Originally posted by Aniruddh
    Why does delete *this calls destructor twice.
    How do we solve this problem

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by Aniruddh
      Why does delete *this calls destructor twice.
      It doesn't. Are you sure you don't call the dtor yourself somewhere else? Have
      you secretly overloaded the 'operator*'?

      kind regards,

      Jos

      Comment

      • Darryl
        New Member
        • May 2007
        • 86

        #4
        Hmm, me thinks you shouldn't be calling delete *this; but instead just delete this;

        Comment

        Working...