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. Deleting objects using abstract base class pointers

Deleting objects using abstract base class pointers

Scheduled Pinned Locked Moved C / C++ / MFC
helpcssdata-structuresdebuggingtutorial
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.
  • D Offline
    D Offline
    Double Ds
    wrote on last edited by
    #1

    Hi, I have an abstract base class Graph which has concrete child classes Grid and Puzzle. To keep the code general, I use pointers to the base class Graph and instantiate them to either Grid or Puzzle objects. This works fine until I have to delete any of these, where I get the "Debug Assertion Failed!", "_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)" error. For example: Grid *g = new Grid(); delete g; works, but Graph *g = new Grid(); delete g; doesn't. Does anybody know why this is? Any help would be greatly appreciated.

    T A 2 Replies Last reply
    0
    • D Double Ds

      Hi, I have an abstract base class Graph which has concrete child classes Grid and Puzzle. To keep the code general, I use pointers to the base class Graph and instantiate them to either Grid or Puzzle objects. This works fine until I have to delete any of these, where I get the "Debug Assertion Failed!", "_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)" error. For example: Grid *g = new Grid(); delete g; works, but Graph *g = new Grid(); delete g; doesn't. Does anybody know why this is? Any help would be greatly appreciated.

      T Offline
      T Offline
      Tim Smith
      wrote on last edited by
      #2

      Is the destructor for your base class virtual? Tim Smith I'm going to patent thought. I have yet to see any prior art.

      D A 2 Replies Last reply
      0
      • D Double Ds

        Hi, I have an abstract base class Graph which has concrete child classes Grid and Puzzle. To keep the code general, I use pointers to the base class Graph and instantiate them to either Grid or Puzzle objects. This works fine until I have to delete any of these, where I get the "Debug Assertion Failed!", "_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)" error. For example: Grid *g = new Grid(); delete g; works, but Graph *g = new Grid(); delete g; doesn't. Does anybody know why this is? Any help would be greatly appreciated.

        A Offline
        A Offline
        Andrzej Markowski
        wrote on last edited by
        #3

        Graph *g = new Grid(); delete g; It works fine for me.

        1 Reply Last reply
        0
        • T Tim Smith

          Is the destructor for your base class virtual? Tim Smith I'm going to patent thought. I have yet to see any prior art.

          D Offline
          D Offline
          Double Ds
          wrote on last edited by
          #4

          Is the destructor for your base class virtual? That was it, thanks. Guess I just don't think of destructors and stuff for abstract classes since they don't get instantiated directly. :sigh: Well, live and learn.

          1 Reply Last reply
          0
          • T Tim Smith

            Is the destructor for your base class virtual? Tim Smith I'm going to patent thought. I have yet to see any prior art.

            A Offline
            A Offline
            Andrzej Markowski
            wrote on last edited by
            #5

            I can't find any relation between the base class virtual/non virtual destructor and delete operator. Could you explain your message?

            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