Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Destructor not being called

Destructor not being called

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpcomquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Miroslav Rajcic
    wrote on last edited by
    #1

    I am having an object inherited from abstract base class (having some pure virtual functions). My problem is this: I create some objects of that type by calling new, and when I later call delete on them destructor is not being called! Destructor is simple (public, not virtual). Is there any open bug in Visual C++ compiler regarding this ? Miroslav Rajcic http://www.spacetide.com

    L 1 Reply Last reply
    0
    • M Miroslav Rajcic

      I am having an object inherited from abstract base class (having some pure virtual functions). My problem is this: I create some objects of that type by calling new, and when I later call delete on them destructor is not being called! Destructor is simple (public, not virtual). Is there any open bug in Visual C++ compiler regarding this ? Miroslav Rajcic http://www.spacetide.com

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Which destructor? If you are talking about the base-class destructor, this is a classic one. The destructor must be virtual

      M 2 Replies Last reply
      0
      • L Lost User

        Which destructor? If you are talking about the base-class destructor, this is a classic one. The destructor must be virtual

        M Offline
        M Offline
        Miroslav Rajcic
        wrote on last edited by
        #3

        Both base class destructor and inherited class destructor are plain public. So, do you say that I must convert one of them to virtual? Miroslav Rajcic http://www.spacetide.com

        C 1 Reply Last reply
        0
        • M Miroslav Rajcic

          Both base class destructor and inherited class destructor are plain public. So, do you say that I must convert one of them to virtual? Miroslav Rajcic http://www.spacetide.com

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          Absolutely - your base class destructor must be virtual. This is how, for example, the designers of the string class stopped people deriving from it, they didn't make the destructor virtual. Christian #include "std_disclaimer.h" People who love sausage and respect the law should never watch either one being made. The things that come to those who wait are usually the things left by those who got there first.

          1 Reply Last reply
          0
          • L Lost User

            Which destructor? If you are talking about the base-class destructor, this is a classic one. The destructor must be virtual

            M Offline
            M Offline
            Miroslav Rajcic
            wrote on last edited by
            #5

            I tried your tip and it works now :) I have declared base class destructor as virtual. Thanks again. Miroslav Rajcic http://www.spacetide.com

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups